Testing if string contains a substring

Oren Tirosh oren-py-l at hishome.net
Wed Apr 23 17:18:45 CEST 2003

On Wed, Apr 23, 2003 at 03:44:57PM +0200, Frantisek Fuka wrote:
> I want a simple test to see if str contains any occurences of substr. I 
> am currently using this:
> import string
> if string.find(str,substr) + 1:
>     ...do something...
> But it somehow looks "ugly" to me. Is there more "standard" way to test 
> this?

if haystack.count(needle):

"If the count of needles in haystack is nonzero then..."


More information about the Python-list mailing list