> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sourcery.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Simplify substring search

#### Sourcery refactoring id: `simplify-substring-search`

#### Description:

Simplify finding if substrings are present in strings by using `in`

#### Before:

```python
my_str = "Hello world"
if my_str.find("ello") == -1:
    print("Not Found!")
```

#### After:

```python
my_str = "Hello world"
if "ello" not in my_str:
    print("Not Found!")
```

#### Before:

```python
my_str = "Hello world"
if my_str.count("ello") > 0:
    print("Found!")
```

#### After:

```python
my_str = "Hello world"
if "ello" in my_str:
    print("Found!")
```

#### Explanation:

Making use of Python's `in` operator for detecting if a substring is present in
a string is more readable than using the `find` or `count` methods, and is also
suggested in the
[documentation](https://docs.python.org/3/library/stdtypes.html#str.find). These
methods are more suitable for cases where you need more information about the
substring's location or the number of times it appears.
