Python Logical Operations
kodingwindow@kw:~$ python3
...
>>> 1 and 1    #1 & 1
1

>>> 1 and 0
0

>>> 0 and 1
0

>>> 0 and 0
0

>>> 1 or 1 #1 | 1 1 >>> 1 or 0 1 >>> 0 or 1 1 >>> 0 or 0 0
>>> True and True #True & True True >>> True and False False >>> False and True False >>> False and False False
>>> True or True #True | True True >>> True or False True >>> False or True True >>> False or False False
>>> not True False >>> not False True
>>> print(True+True) 2 >>> print(True-False) 1 >>> print(False-True) -1
>>> 1==1 True >>> 1<1 False >>> 1>1 False >>> 1>=1 True >>> 10//30==1//3 True >>> -0.0==0.0 True
>>> a='Hello' >>> b='hello' >>> a==b False >>> b='Hello' >>> a==b True
Advertisement