Testing if string contains a substring

Jeremy Fincher tweedgeezer at hotmail.com
Wed Apr 23 21:41:39 CEST 2003

Alex Martelli <aleax at aleax.it> wrote in message news:<NKxpa.85054$T34.2112670 at news2.tin.it>...
> However, such new functionality doesn't get back-ported to previous
> releases of Python, such as 2.2.*.  In all Python releases from 1,6
> included to 2.3 excluded, "needle.find(haystack) > 0" is the idiom.
> Module string is needed if you want to use antediluvian versions of
> Python, such as 1.5.2, where strings didn't have methods.

Of course, you  meant "haystack.find(needle) >= 0", right?

I always use (and have seen used) "haystack.find(needle) != -1", myself.


More information about the Python-list mailing list