question about True values
robert.kern at gmail.com
Wed Oct 25 21:19:34 CEST 2006
John Salerno wrote:
> I'm a little confused. Why doesn't s evaluate to True in the first part,
> but it does in the second? Is the first statement something different?
> >>> s = 'hello'
> >>> s == True
> >>> if s:
> print 'hi'
They are, indeed, quite different things. Finding the truth value of an object
is not the same thing as testing if the object is equal to the object True. When
people use the phrase "evaluate to True" in the context of an if: statement,
they mean that the truth value of the object (found using the special method
.__nonzero__()) is True, not that it is equal to True.
It's a bit of an abuse on the English language, but what isn't in software?
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the Python-list