The in keyword can be used to check if a particular substring exists in another string. If the substring is found, the operation returns true.
Here’s how it works:
An alternative for finding a substring using the in keyword is the find() method. It returns the first index at which a substring occurs in a string. If no instance of the substring is found, the method returns -1.
-1 is a conventional value that represents a None or failure in case the output was supposed to be positive.
For a string called a_string, find() can be used in the following way:
a_string.find(substring, start, end)
substring is what we are searching for.
start is the index from which we start searching in a_string.
end is the index where we stop our search in a_string.
start and end are optional.