Here is a simple approach:
my_string = 'abcdefg'
print(text.find('def'))
Output:
3
I the substring is not there, you will get -1. For example:
my_string = 'abcdefg'
print(text.find('xyz'))
Output:
-1
Sometimes, you might want to throw exception if substring is not there:
my_string = 'abcdefg'
print(text.index('xyz')) # It returns an index only if it's present
Output:
Traceback (most recent call last):
File "test.py", line 6, in print(text.index('xyz'))
ValueError: substring not found