Logical operators python3

1、and

  "And" if x is False, x and y returns False, else it returns evaluation of y. 

10 <. 1 and . 3>. 1        # 10 <. 1 to False, so whole False 
--------------------------- 
False
10> 1 and 3> 1    # 10> 1 is True, so look Boolean 3> 1 and 3> 1 True, the overall value of True. 
--------------- -------------------------------------------------- ----------------------- 
True

 

2、or

  "Or" if x is non-zero, it returns the value of x. Otherwise, it returns the calculated value of y.

10> 1 or . 3> 1.   # 10> 1 bit True, the Boolean value 10 directly> 1. 
-------------------------------------------------- -------------- 
True
10 <1 or . 3> 1.       # Because 10 <1 False, 3 return> Boolean value 1. 
-------------------------------------------------- --------------- 
True

 

3、not

  "Non" - If x is True, it returns False. If x is False, it returns True.

not True 
--------------------------
False

 

4, the priority of logical operators

  From left to right :()> not> and> or

计算:1>3 or 3>2 and 1=0 and not(7>2 or 3>5)

  answer:

  From left to right, first calculate (), the 7> 2 is True, then the parentheses is True, looking outside the parentheses not, then this part # is false.
  And then to calculate the left and, 3> 2 is True, See the Boolean value 1 = 0, 1 = 0 to False, 3> 2 and 1 = 0 is #False.
  recalculation 3> 2 and 1 = 0 and not (7> 2 or 3> 5), known 3> 2 and 1 = 0 is False, not (7> 2 or 3> 5) to False, 3> 2 and 1 = 0 and not (7> 2 or 3> 5) to False.
  Finally, see 1> 3 False, 3> 2 and 1 = 0 and not (7> 2 or 3> 5) False, the whole False.

Guess you like

Origin www.cnblogs.com/490144243msq/p/11031867.html