Python Mastery – From Basics to Brilliance / Operators in Python

Logical Operators

Used to combine multiple conditions and return a Boolean result — True or False.

They help your program make decisions based on more than one condition.


Operator

What It Does

Example

and

Returns True only if both conditions are True

a > 5 and b < 10

or

Returns True if at least one condition is True

x == 1 or x == 2

not

Reverses the result. True becomes False, and vice versa

not(True) → False


and Logical AND

x = 5
x > 3 and x < 10 # Output: True

or Logical OR

x = 5
x > 10 or x < 10 # Output: True

not Logical NOT

x = 5
not (x > 3) # Output: False