rfind bug ?

Chris Rebert clp2 at rebertia.com
Wed Apr 21 04:56:41 EDT 2010


On Wed, Apr 21, 2010 at 1:51 AM, Stef Mientki <stef.mientki at gmail.com> wrote:
> With the following code, I would expect a result of 5 !!
>
>>>> a= 'word1 word2 word3'
>>>> a.rfind(' ',7)
> 11
>
> Is this a bug ?

No. Don't you think someone would have found such an obvious bug by now?

You want regular str.find(), which searches from left-to-right:
>>>> a= 'word1 word2 word3'
>>> a.find(' ')
5

str.rfind() is a variant of str.find() that searches from
right-to-left. The "r" is for "right".

Cheers,
Chris
--
http://blog.rebertia.com



More information about the Python-list mailing list