# How to check if a string contains a substring in Python?

There are multiple ways to check if a string contains a specific substring.

## Using in keyword

You can use in keyword to check if a string contains a specific substring. The expression will return boolean value.

```python
if 'Stack' in 'BetterStack':
	print('Found it!')
else:
	print('Did not found it!')
```

The general syntax is the following:

```python
if substring in string:
	# substring is in string
else
	# substring is not in string
```

## Using the `String.index`

You can also use `String.index` method to find specific the index in the string where the substring starts.

```python
string = 'BetterStack'
substring = 'Stack'

try:
    string.index(substring)
except ValueError:
    print('Not found!')
else:
    print('Found it!')
```

## Using the `String.find`

Also, you can use the `find` function from the String class. This function will return `-1` if the substring is not present in the string.

```python
string = 'BetterStack'
substring = 'Stack'

if string.find(substring) != -1:
    print('Found it!')
else:
    print('Not found!')
```