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

jelle feringa jelleferinga at gmail.com
Wed Oct 31 10:55:49 EDT 2007


There is a subtle point though.
If the substring is not found '_'.find(' '), will return -1
Semanticly, I was expecting the that if the substring was not found, the
conditional statement would not be found.
However, python evaluates -1 to True, so that is what I do find confusing.
So, I was arguing that '_'.find(' ') might return 0, however that is
obviously ambigious, since 0 might be an index as well.

So, perhaps I should rephrase and ask, why if -1 evaluates to True?
I think that's pretty ugly...

cheers,

-jelle
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20071031/6dd4ce05/attachment.html>


More information about the Python-list mailing list