A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2002-August/027418.html below:

[Python-Dev] Dafanging the find() gotcha

[Python-Dev] Dafanging the find() gotcha [Python-Dev] Dafanging the find() gotchaPatrick K. O'Brien pobrien@orbtech.com
Mon, 5 Aug 2002 19:05:53 -0500
[Tim Peters]
>
>     s2.find(s1)
>
> returns the smallest non-negative int i such that
>
>     s2[i : i+len(s1)] == s1  # Fixed typo in original.
>
> provided such an i exists.  That's as sensible as any answer, and more
> sensible than most <wink>, if you have to give a meaning when s1 is empty.

That clarified things for me, thanks.

(But if you squint while thinking about finding single characters and using
the result to access the original string via index notation, rather than
slice, and you ignore the fact that '' isn't even a single character and you
do this late in the day... you might see why I wasn't seeing the logic of
'whatever'.find('') returning 0.)

--
Patrick K. O'Brien
Orbtech
-----------------------------------------------
"Your source for Python programming expertise."
-----------------------------------------------
Web:  http://www.orbtech.com/web/pobrien/
Blog: http://www.orbtech.com/blog/pobrien/
Wiki: http://www.orbtech.com/wiki/PatrickOBrien
-----------------------------------------------




RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4