[Tutor] checking substrings in strings

Frank Hoffsümmer frank.hoffsummer at gmx.de
Thu Aug 25 01:34:54 CEST 2005


Hello,
I would like to check if a certain word exists in a given string.  
since I learned to love lists, I used

if myword in mystring:

...didnt work. I have now resorted to

if mystring.find(myword) >1:

is this really the canonical way to check if myword exists in mystring?
it feels somewhat "unpythonic", thats why I'm asking

thanks for any insight you might have
-frank


More information about the Tutor mailing list