لَآ إِلَـٰهَ إِلَّا هُوَ
LA ILAHA ILLA HU
Allah, Your Lord There Is No Deity Except Him.

Lesson 13: Comparison Operators In Python

Comparison Operators In Python are used to compare two values.

Operator Name Example
== Equal x == y

Illustration

x = 4
y = 2
print(x == y)
the out put will be
False
Note: Returns False because 4 is not equal to 2.

Operator Name Example
!= Not equal x != y

Illustration

x = 4
y = 2
print(x != y)
the output will be
True

Note: Returns True because 4 is not equal to 2.

Operator Name Example
> Greater than x > y

Illustration

x = 4
y = 2
print(x > y)
the output will be
True
Note: Returns True because 4 is greater than 2

Operator Name Example
< Less than x < y

Illustration

x = 4
y = 2
print(x < y)
the output will be
False
Note: Returns False because 4 is not less than 2.

Operator Name Example
>= Greater than or equal to x >= y

Illustration

x = 4
y = 2
print(x >= y)
the output will be
True
Note:returns True because 4 is greater, or equal, to 2.

Operator Name Example
<= Less than or equal to x <= y

Illustration

x = 4
y = 2
print(x <= y)

the output will be
False
Note: Returns False because 4 is neither less than or equal to 2.