logical operators in python


Python supports 3 logical operators:




or

and

not



x or y If the first argument, x, is false, then it evaluates the second argument, y. Else, it evaluates x.



x and y




If x is false, then it evaluates x. Else, if x is true, it evaluates y.




not x




If x is false, then it returns True. If x is true, it returns False.






Examples:



>>> (8>9) and (2<9) False


>>> (2>1) and (2>9) False


>>>  (2==2) or (9<20)

True



>>> (3!=3) or (9>20) False




>>> not (8 > 2)

False



>>> not (2 > 10)

True

Comments