Does Python has a string method called str.contains(substring)
that checks whether a string contains a given substring? Suppose I have the string I like to do programming
and I want to check that string contains the word programming
. I have found the find
method that returns the index of the first occurrence of the substring in the string. If the substring is not found, find
returns -1
. But I want to check it with the str.contains()
method if it exists in Python.
Here is the code that I found:
Can someone explain to me whether Python has a string method called str.contains(substring)
or not? Does any Python library provide this method to check whether a string contains a given substring?