[Tutor] if item.find(extension)!= -1: -- what's the -1?

Wayne Werner waynejwerner at gmail.com
Sat Feb 6 17:50:00 CET 2010


On Sat, Feb 6, 2010 at 10:35 AM, David <ldl08 at gmx.net> wrote:

> Hello again,
>
> in Knowlton's 2008 book "Python: Create, Modify, Reuse" the author makes
> frequent use of the term -1 in his code, but doesn't tell to what aim. For
> want of search terms Google is not helpful. Could someone please enlighten
> me by means of a one-liner as a reply?
>
>
In [1]: item = 'some string'

In [3]: help(item.find)
Help on built-in function find:

find(...)
    S.find(sub [,start [,end]]) -> int

    Return the lowest index in S where substring sub is found,
    such that sub is contained within s[start:end].  Optional
    arguments start and end are interpreted as in slice notation.

    Return -1 on failure.

HTH,
Wayne



> Thank you!
>
> David
>
>
> Example Code:
>
> for item in filelist:
>        if item.find(extension)!= -1:
>            snaplist.append(item)
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn’t. - Primo Levi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100206/3c064e19/attachment.htm>


More information about the Tutor mailing list