Why does the expression 0 < 0 == 0 return False in Python?

前端 未结 9 1556
误落风尘
误落风尘 2020-11-22 01:48

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         


        
9条回答
  •  长发绾君心
    2020-11-22 02:26

    >>> 0 < 0 == 0
    False
    

    This is a chained comparison. It returns true if each pairwise comparison in turn is true. It is the equivalent to (0 < 0) and (0 == 0)

    >>> (0) < (0 == 0)
    True
    

    This is equivalent to 0 < True which evaluates to True.

    >>> (0 < 0) == 0
    True
    

    This is equivalent to False == 0 which evaluates to True.

    >>> 0 < (0 == 0)
    True
    

    Equivalent to 0 < True which, as above, evaluates to True.

提交回复
热议问题