list index()

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Thu Aug 30 22:12:41 CEST 2007


On Thu, 30 Aug 2007 09:41:00 -0700, zzbbaadd wrote:

> On Aug 30, 12:09 am, Ben Finney <bignose+hates-s... at benfinney.id.au>
> wrote:
>> zzbba... at aol.com writes:
>> > What's with the index() function of lists throwing an exception on not
>> > found?
>>
>> It's letting you know that the item isn't in the list. There's no
>> sensible return value from an "index" function in that condition.
> 
> for str:
> 
> find(  	sub[, start[, end]])
>     Return the lowest index in the string where substring sub is
> found, such that sub is contained in the range [start, end]. Optional
> arguments start and end are interpreted as in slice notation. Return
> -1 if sub is not found.

But that is a valid index into a string!  So this may go unnoticed if one
doesn't check after every call to `str.find()`.  And that method is going
away in Python 3.0.

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list