Why do rfind and find return the same values in Python 2.6.5?
Question: I'm relatively new to Python, and something is acting up. Basically, when I
call `str.rfind("test")` on a string, the output is the same as
`str.find("test")`. It's best that I show you an example:

    
    
    Python 2.6.5 (r265:79063, May  6 2011, 17:25:59) 
    [GCC 4.5.0 20100604 [gcc-4_5-branch revision 160292]] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import string
    >>> line = "hello what's up"
    >>> line.rfind("what")
    6
    >>> line.find("what")
    6
    

By my understanding, the value of `line.find` is okay, but the value of
`line.rfind` should be `9`. Am I misinterpreting these functions or not using
them well?


Answer: I think you're expecting `rfind` to return the index of the rightmost
character in the first/leftmost match for `"what"`. It actually returns the
index of the leftmost character in the last/_rightmost_ match for `"what`". To
quote [the
documentation](http://docs.python.org/2.7/library/stdtypes.html#str.rfind):

> ### `str.rfind(sub[, start[, end]])`
>
> Return the highest index in the string where substring _sub_ is found, such
> that _sub_ is contained within `s[start:end]`. Optional arguments _start_
> and _end_ are interpreted as in slice notation. Return `-1` on failure.

`"ab c ab".find("ab")` would be `0`, because the leftmost occurrence is on the
left end.  
`"ab c ab".rfind("ab")` would be `5`, because the rightmost occurrence is
starts at that index.

