Just remember that Python is sexy

Peter Hansen peter at engcorp.com
Thu May 26 07:51:15 EDT 2005


Ville Vainio wrote:
>>>>>>"Peter" == Peter Hansen <peter at engcorp.com> 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?

Ah, is that what Sion meant by "which way around"?  Obviously that was 
an ambiguous question, since I thought he was referring to the order of 
the arguments.

My answer to the other question, unfortunately, is "I just type one of 
them at an interpreter prompt and see which result I get".  Much faster 
than checking the docs...    ;-)

-Peter



More information about the Python-list mailing list