Ville Vainio wrote:

>>>>>> "Peter" == Peter Hansen <[EMAIL PROTECTED]> writes:
> 
>     Peter> Sion Arrowsmith wrote:
>     >> But can you come up with a method for remembering which way
>     >> round str.find() and str.index() are?
> 
>     Peter> Don't use "str" and you won't have anything to remember:
> 
>     Peter> 'foo bar baz'.find('spam')
>     Peter> 'spanish inquisition'.index('parrot')
> 
> But which one raises an exception, and which one returns -1?
> 
The name index implies it returns something you can use as an index to get 
at the substring.

In other words you can always assume that the following expression is True 
(if it has any value at all) when you use the result of index as an index:

    s[s.index(t):].startswith(t)

The name 'find' doesn't really imply anything about the result, so it can 
return pretty much any crud such as -1.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to