Python - Check If Word Is In A String

The Woo picture The Woo · Mar 16, 2011 · Viewed 774.5k times · Source

I'm working with Python v2, and I'm trying to find out if you can tell if a word is in a string.

I have found some information about identifying if the word is in the string - using .find, but is there a way to do an IF statement. I would like to have something like the following:

if string.find(word):
    print 'success'

Thanks for any help.

Answer

fabrizioM picture fabrizioM · Mar 16, 2011

What is wrong with:

if word in mystring: 
   print 'success'