True = T
False = F
Not |
Not X |
Boolean "Non"-returns False if X is True. If X is False, it returns TRUE. |
Not (A and B) returns False |
?
and |
X and Y |
Boolean "and"-if x is False,x and y returns FALSE, otherwise it returns the computed value of Y. |
(A and B) returns. |
?
Or |
X or Y |
Boolean "or"-if X is non-0, it returns the value of x, otherwise it returns the computed value of Y. |
(A or B) return |
?
(A and B) or (C and (not D))
=false or (True and true)
=false or True
=true
------------------------------------------------------------------------
#and or not
#优先级, () > Not > and > or
# print (2 > 1 and 1 < 4)
# print (2 > 1 and 1 < 4 or 2 < 3 and 9 > 6 or 2 < 4 and 3 < 2)
# T or T or F
#T or F
# print (3>4 or 4<3 and 1==1) # F
# Print (1 < 2 and 3 < 4 or 1>2) # T
# print (2 > 1 and 3 < 4 or 4 > 5 and 2 < 1) # T
# print (1 > 2 and 3 < 4 or 4 > 5 and 2 > 1 or 9 < 8) # F
# print (1 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6) # F
# print (not 2 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6) # F
#ps int----> BOOL non 0 converts to bool True 0 converts to bool is false
# Print (bool (2))
# Print (bool (-2))
# print (bool (0))
# #bool--->int
# print (int (True)) # 1
# print (int (False)) # 0
"' X or y x True, then return x '"
# print (1 or 2) # 1
# print (3 or 2) # 3
# print (0 or 2) # 2
# print (0 or 100) # 100
# Print (2 or 3 or 4) # 2
# print (0 or 4 and 3 or 2)
"' X and y x True, then return y ' '
# Print (1 and 2)
# print (0 and 2)
Print (2 or 1 < 3) #2
Print (3 > 1 or 2 and 2) #True
Python logical operators