how to check if something is in a string python code example
Example 1: if substring not in string python
fullstring = "StackAbuse"
substring = "tack"
if fullstring.find(substring) != -1:
print "Found!"
else:
print "Not found!"
Example 2: python str contains word
fullstring = "StackAbuse"
substring = "tack"
if substring in fullstring:
print "Found!"
else:
print "Not found!"
Example 3: how to check a string in if statement python
if var in ('stringone', 'stringtwo'):
dosomething()
Example 4: how to check a string in if statement python
if var in ['string one', 'string two']:
do_something()