Re: shouldn't 'string'.find('ugh') return 0, not -1 ?
- From: Marc 'BlackJack' Rintsch <bj_666@xxxxxxx>
- Date: 31 Oct 2007 14:22:45 GMT
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
.
- References:
- Prev by Date: Re: shouldn't 'string'.find('ugh') return 0, not -1 ?
- Next by Date: Re: why did these companies choose Tcl over Python
- Previous by thread: Re: shouldn't 'string'.find('ugh') return 0, not -1 ?
- Next by thread: Re: shouldn't 'string'.find('ugh') return 0, not -1 ?
- Index(es):