Search code snippets, questions, articles...

Python - String , Check If Word Is In string

if word in mystring: 
   print ('success')

# or

if 'seek' in 'those who seek shall find':

but keep in mind that this matches a sequence of characters, not necessarily a whole word - for example, 'word' in 'swordsmith' is True. If you only want to match whole words, you ought to use regular expressions:

Was this helpful?
Programming Feeds
Learn something new everyday on Devsheet