Testing if string contains a substring
Frantisek Fuka
fuka at fuxoft.cz
Thu Apr 24 05:26:02 EDT 2003
Many thanks to everyone. Can I get the "new" string functions
explanation somewhere? I have Python 2.2.2 but the current documentation
only seems to mention the old-style STRING module...
Alex Martelli wrote:
> Jeremy Fincher wrote:
>
>
>>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?
>
>
> Yes, sorry. See my response to Bengt as to why I was confused
> between needle-on-left and haystack-on-left;-).
>
>
>
>>I always use (and have seen used) "haystack.find(needle) != -1", myself.
>
>
> I never saw any added value in that one extra character -- if I did
> want to use -1 I would also use > rather than != ...;-)
>
>
> Alex
>
More information about the Python-list
mailing list