Why is 'True == not False' a syntax error in Python?

前端 未结 3 1248
难免孤独
难免孤独 2020-12-03 09:33

Comparing boolean values with == works in Python. But when I apply the boolean not operator, the result is a syntax error:

Python 2         


        
3条回答
  •  盖世英雄少女心
    2020-12-03 10:14

    I think what you are looking for is "and not". This gives you the results you are looking towards. If your comparing booleans what you have is a compound boolean expression, here is an example website Compound Boolean Expression.

    >>> True and True
    True
    >>> True and not True
    False
    >>> True and not False
    True
    >>> False and not True
    False
    >>> False and not False
    False
    >>> False and False
    False
    

提交回复
热议问题