Logical Operators

In Python, Logical operators are used on conditional statements (either True or False). They perform Logical AND, Logical OR and Logical NOT operations.

Example 1: Logical operators in Python

x = True
y = False

print('x and y is',x and y)

print('x or y is',x or y)

print('not x is',not x)

Output:

x and y is False
x or y is True
not x is False

and will result into True only if both the operands are True

The truth table for and is given below:

or will result into True if any of the operands is True.

The truth table for or is given below:

not operator is used to invert the truth value.

The truth table for not is given below:

some example of their usage are given below

>>> True and False
False
>>> True or False
True
>>> not False
True

Last updated