list index()

MRAB google at mrabarnett.plus.com
Thu Aug 30 15:13:23 EDT 2007


On Aug 30, 5:41 pm, zzbba... at aol.com 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.
>
> -1 is used in other languages as well.

In 0-based languages it's often -1 whereas in 1-based languages it's
often 0.




More information about the Python-list mailing list