And Or not
Priority: () > and > or > Not
1.or
In Python, the logical operator or,x or y, if X is true, returns X if X is false to return the Y value. Because if X is true then the or operation exits to see L, one is true, so the value of x is returned. If the value of X is false, then the result of the or operation depends on Y, so the value of Y is returned.
1 Print or 2) # 12printor 2) # 33 printor 2) # 24printor # - 5 Print or 0)
2.and
In Python, the logical operator and,x and y, and if x is true, returns the Y value. If x is false, the Y value is returned. If the value of X is True,and the operation does not end, the value of Y continues to be seen, so true and false depends on the value of Y, so if X is true, then the value of Y is returned. If x is false, then the and operation ends the operation because there is a false and false, so the value of x is returned.
Print and 2) # 2print and 0) # 0Print and 2) # 0print and 2) # 2 Print and 0) # 0
3. Mixing examples and parsing
Print and or and 3 < 2) # false or False
In the case of a left-hand, high-priority rule, first, because the comparison operator takes precedence over the logical operator, it is simple to do so if the operator is lower than the logical operator precedence. and priority is greater than or
1 > 2 is False
3 < 2 is False
Flase and 3, because false is false so and does not return the operation directly false
4 and False, because 4 is true so the AND operator continues the operation, with false as the primary, so returns false.
False or False because false is false, so the OR operator will continue after the operation, with false as the primary, so return the false value after
Python logical operators