Re: shouldn't 'string'.find('ugh') return 0, not -1 ?
- From: Luis Zarrabeitia <kyrie@xxxxx>
- Date: Wed, 31 Oct 2007 15:34:06 +0000
the subject pretty much says it all.
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?
I belive str.find should return the first position where the substring appears.
If "string".find("ugh") were to return 0, how would you differentiate from
"ugh".find("ugh")? That one *should* return 0.
this breaks the
if check.find('something'):
do(somethingElse)
idiom, which is a bit of a pity I think.
It breaks the idiom because you are speaking the wrong language.
You should be doing:
if "something" in "string":
do(something())
wich is clearer IMHO.
cheers,
-jelle
See ya,
--
Luis Zarrabeitia
Facultad de Matemática y Computación, UH
http://profesores.matcom.uh.cu/~kyrie
--
http://mail.python.org/mailman/listinfo/python-list
--
"Al mundo nuevo corresponde la Universidad nueva"
UNIVERSIDAD DE LA HABANA
280 aniversario
.
- Prev by Date: Re: Python bug tracker now secret?
- Next by Date: Re: Creating a temporary file in 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):
Relevant Pages
|