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

Looney, James B james.b.looney at
Wed Oct 31 16:04:19 CET 2007

I believe most programming languages evaluate 0 to mean False, and
anything else to be True (for the purposes of boolean evaluation).
Python is no exception.


	From: at
[ at] On
Behalf Of jelle feringa
	Sent: Wednesday, October 31, 2007 8:56 AM
	To: Luis Zarrabeitia
	Cc: python-list at
	Subject: Re: shouldn't 'string'.find('ugh') return 0, not -1 ?
	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
	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
	I think that's pretty ugly...

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list