shouldn't 'string'.find('ugh') return 0, not -1 ?

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Wed Oct 31 10:22:45 EDT 2007


On Wed, 31 Oct 2007 13:31:06 +0000, jelle wrote:

> if I check a string for for a substring, and this substring isn't found, 
> should't the .find method return 0 rather than -1?
> this breaks the 
> 
> if check.find('something'):
>     do(somethingElse)
> 
> idiom, which is a bit of a pity I think.

And what should ``'string'.find('str')`` return?  How do you distinguish
the not found at all case from the found at the very beginning case!?

The simple test you want can be written this way:

if 'something' in check:
    do(something_else)

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list