Search String for Word

Tim Chase python.list at
Mon Jun 26 16:55:41 CEST 2006

> What's the best way to search a string for a particular word and get a
> booleen value indicating whether it exists in the string or not?

 >>> substring = 'foo'
 >>> targetstring = 'blah foo bar'
 >>> substring in targetstring
 >>> if substring in targetstring: print 'yup'


More information about the Python-list mailing list