Does Python have a string ‘contains’ substring method?
Explanation
Yes, Python has a string ‘contains’ substring method. So that if it’s just a substring search you can use
string.find("substring")
.And also you have to be a little careful with find
, index
, and in
though. Because they all are substring searches. Or we can say that in other words, they are:
s = "This be a string"
if s.find("is") == -1:
print("No 'is' here!")
else:
print("Found 'is' in the string.")
So that it would print Found 'is' in the string.
Similarly, if "is" in s:
would evaluate to True
. This is something that you may or may not be what you want.
Also read, Consider a database containing personal information