1fullstring = "StackAbuse"
2substring = "tack"
3
4if fullstring.find(substring) != -1:
5 print "Found!"
6else:
7 print "Not found!"
8
1>>> str = "Messi is the best soccer player"
2>>> "soccer" in str
3True
4>>> "football" in str
5False
1fullstring = "StackAbuse"
2substring = "tack"
3
4if substring in fullstring:
5 print "Found!"
6else:
7 print "Not found!"
1def find_string(string,sub_string):
2 return string.find(sub_string)
3#.find() also accounts for multiple occurence of the substring in the given string
1myString = "<text contains this>"
2myOtherString = "AnotherString"
3
4# Casting to string is not needed but it's good practice
5# to check for errors
6
7if str(myString) in str(myOtherString):
8 # Do Something
9else:
10 # myOtherString didn't contain myString
11