Looking into Queue.py in Python 2.6, I found this construct that I found a bit strange:
def full(self):
\"\"\"Return True if the queue is full, False oth
Because
(0 < 0) and (0 == 0)
is False
. You can chain together comparison operators and they are automatically expanded out into the pairwise comparisons.
EDIT -- clarification about True and False in Python
In Python True
and False
are just instances of bool
, which is a subclass of int
. In other words, True
really is just 1.
The point of this is that you can use the result of a boolean comparison exactly like an integer. This leads to confusing things like
>>> (1==1)+(1==1)
2
>>> (2<1)<1
True
But these will only happen if you parenthesise the comparisons so that they are evaluated first. Otherwise Python will expand out the comparison operators.