On Sat, Jul 12, 2008 at 8:10 PM, Dick Moores <[EMAIL PROTECTED]> wrote:
- But why will a tuple with two elements will always evaluate to
- True?
- In [2]: (3,5) == True
- Out[2]: False
- In [3]: ("qwerty", "asdfg") == True
- Out[3]: False
- In [4]:
The value formally known as True is only one member of the set of things that don't evaluate to False... Confused yet?
Anyway, this might make it a bit clearer:
>>> (3,2) == True
False
>>> if (3,2): print "Tru, dat"
...
Tru, dat
>>>
In other words, "(3,2)" isn't exactly the same as "True" - but it doesn't evaluate to False, either, so it's true.
So what does (3,2) evaluate to? Or is that a meaningless question? However in the following example, "What does z evaluate to?" seems to have a meaning, and the answer is not "True" or "False". z evaluates to 12, right? Or is there an ambiguity in "evaluate" in Python that is well-understood and doesn't cause a problem?
In [28]: x,y = 3,4
In [29]: z = x*y
In [30]: z
Out[30]: 12
In [31]: bool(z)
Out[31]: True
In [32]: z == True
Out[32]: False
In [33]: z == False
Out[33]: False
Dick
_______________________________________________ Tutor maillist - [email protected] http://mail.python.org/mailman/listinfo/tutor
