Last Minute Python Logical Operators and Priority Tutorial

Python Logical Operators Truth Table

Python language supports Logical operators to form complex conditions. These are different from the logical operators used in C and Java. Let us know more in this Last Minute Python Logical operators and priority tutorial using examples.

Note 1: Python Logical Operators are NOT Symbols but keywords. Also, remember that a logical operation may result in either a Boolean or bool type value or an object.

Note 2: Python Logical operators and Boolean operators are different. In C and Java, boolean and logical operations are one and the same.

Python Logical Operators

Python supports 3 logical operators namely "and", "or" and "not". The first letter of each logical operator's name is not capitalized. These operators allow you to create compound conditions that contain two or more conditions.

These logical operators can be used inside an IF, ELIF and WHILE constructs.

In other words, you can group a number of individual conditions into a single complex condition using these logical operators.

Any non-zero value is considered as True in Python and a zero value is considered as False. So a single condition may contain Arithmetic Operations, Relational Operations or direct Objects.

Python logical operators work with two operands namely left-operand and right-operand in general.

List of Python Logical Operators:

SNO Logical Operator
1. and
2 or
3. not

1. AND Logical Operator

If the left operand is False, the output is False. If the left operand is True, the output depends on the right-operand. So, the "and" operator exhibits short-circuit behaviour.

And Truth Table:

Value1(x) Value2(y) Output
False False x
False True x
True False y
True True y


a=10; b=20; c=0;

print(a and b)

if(a and b):

print(c and a)
if(c and a):
#no output

2. OR Logical Operator

If the left operand is True, the output is True. If the left operand is false, the output depends on the right-operand. So, the "or" operator exhibits short-circuit behaviour.

Or Truth Table:

Value1(x) Value2(y) Output
False False y
False True y
True False x
True True x


x=20; y= 30; z=0;
print(x or y)

print(z or y)

3. NOT Logical Operator

The Not operator returns the opposite of the input boolean value i.e True for False and False for True.

Not Truth Table:

Value Output
True False
False True


p=30; k=0;

print(not p)

print(not k)

if(not k):

Python Logical Operator Priority or Precedence

Python Logical "not" operator has the highest priority among the three operators. The logical "and" operator has the least priority.

If two or more logical operations are present in a compound condition, the order of evaluation is from left to right.

The logical operators' group has a lesser priority than Arithmetic operators, Bitwise operators, Relational operators and Assignment operators.

Python Logical Operator Priority table is given below.

Logical Operator Priority
not 1
or 2
and 3

In the coming chapters, you will know how to use Python Boolean operators.

Share this Last Minute Python tutorial on Logical Operators and their Priority with your friends and colleagues to encourage authors.



Show some care. Like or Subscribe.

C MCQ App by ExamTray 

EXAMTRAY C MCQ android app link
ALL MCQ App by ExamTray EXAMTRAY android app link