namespace issue?
Remco Gerlich
scarblac at pino.selwerd.nl
Fri Jun 22 05:14:07 EDT 2001
Pierre Fortin <pfortin at pfortin.com> wrote in comp.lang.python:
> Michael Powe wrote:
> > So now the question is, 'why'? Am I misusing the string.find()
> > function? Okay, string.find() returns -1 when the string is not found,
> > which would seem to be what I expected, a false result. Maybe python
> > doesn't treat -1 as false? Well, I'll try being explicit and testing
> > for -1 return. I probably have just confused myself hopelessly.
>
> Sometimes -1 is used for failure; BUT -1 is NOT false... in those cases, you
> can simply add 1 to the return to force a failure to return 0 (false)...
Eek, how unobvious.
I like
if s.find("bla") != -1:
a lot better than
if s.find("bla")+1:
The second one takes two steps to understand, in my mind.
--
Remco Gerlich
More information about the Python-list
mailing list