# What are boolean operators in Python?

PythonServer Side ProgrammingProgramming

The logical operators and, or and not are also referred to as boolean operators. While and as well as or operator needs two operands, which may evaluate to true or false, not operator needs one operand evaluating to true or false.

Boolean and operator returns true if both operands return 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

Boolean or operator returns true if any one 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

The not operator returns true if its operand is a false expression and returns false if it is true.

>>> a=10
>>> a>10
False
>>> not(a>10)
True


Published on 13-Feb-2018 05:36:44