Just remember that Python is sexy
Sion Arrowsmith
siona at chiark.greenend.org.uk
Thu May 26 08:10:28 EDT 2005
Duncan Booth <duncan.booth at suttoncourtenay.org.uk> wrote:
>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?
That's what I meant (and why I wrote "str." not "string.").
>The name index implies it returns something you can use as an index to get
>at the substring.
Unfortunately, -1 can of course be used as an index. Mind you, it
would be perverse to expect to find the substring at it.
--
\S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/
___ | "Frankly I have no feelings towards penguins one way or the other"
\X/ | -- Arthur C. Clarke
her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
More information about the Python-list
mailing list