What is different in OR and AND operators in Python?

PythonServer Side ProgrammingProgramming

In Python, and and or (along with not) are defined as logical operators. Both require two operands which may evaluate to true or false.

The and operator returns True only if both operands are True.

>>> a=50
>>> b=25
>>> a>40 and b>40
False
>>> a>100 and b<50
False
>>> a==0 and b==0
False
>>> a>0 and b>0
True

The or operator returns True if either operand is true.

>>> a=50
>>> b=25
>>> a>40 or b>40
True
>>> a>100 or b<50
True
>>> a==0 or b==0
False
>>> a>0 or b>0
True
Published on 13-Feb-2018 05:17:14