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

Looney, James B james.b.looney at lmco.com
Wed Oct 31 11:04:19 EDT 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: python-list-bounces+james.b.looney=lmco.com at python.org
[mailto:python-list-bounces+james.b.looney=lmco.com at python.org] On
Behalf Of jelle feringa
	Sent: Wednesday, October 31, 2007 8:56 AM
	To: Luis Zarrabeitia
	Cc: python-list at python.org
	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
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/476cced4/attachment.html>


More information about the Python-list mailing list