The Wayback Machine - https://web.archive.org/web/20240118180706/https://www.geeksforgeeks.org/relational-operators-in-python/
Open In App
Related Articles

Relational Operators in Python

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

Relational operators are used for comparing the values. It either returns True or False according to the condition. These operators are also known as Comparison Operators.

Operator

Description

Syntax

>

Greater than: True if the left operand is greater than the right x > y

<

Less than: True if the left operand is less than the right x < y

==

Equal to: True if both operands are equal x == y

!=

Not equal to – True if operands are not equal x != y

>=

Greater than or equal to: True if left operand is greater than or equal to the right x >= y

<=

Less than or equal to: True if left operand is less than or equal to the right x <= y

Now Let’s see each Relational Operator one by one.

1) Greater than: This operator returns True if the left operand is greater than the right operand.

Syntax:

x > y

Example:

Python3




a = 9
b = 5
  
# Output
print(a > b)


Output:

True

2) Less than: This operator returns True if the left operand is less than the right operand.

Syntax:

x < y

Example:

Python3




a = 9
b = 5
  
# Output
print(a < b)


Output:

False

3) Equal to: This operator returns True if both the operands are equal i.e. if both the left and the right operand are equal to each other.

Example:

Python3




a = 9
b = 5
  
# Output
print(a == b)


Output:

False

4) Not equal to: This operator returns True if both the operands are not equal.

Syntax:

x != y

Example:

Python3




a = 9
b = 5
  
# Output
print(a != b)


Output:

True

5) Greater than or equal to: This operator returns True if the left operand is greater than or equal to the right operand.

Syntax:

x >= y

Example:

Python3




a = 9
b = 5
  
# Output
print(a >= b)


Output:

True

6) Less than or equal to: This operator returns True if the left operand is less than or equal to the right operand.

Syntax: 

x <= y

Example:

Python3




a = 9
b = 5
  
# Output
print(a <= b)


Output:

False

Don't miss your chance to ride the wave of the data revolution! Every industry is scaling new heights by tapping into the power of data. Sharpen your skills, become a part of the hottest trend in the 21st century.
Dive into the future of technology - explore the Complete Machine Learning and Data Science Program by GeeksforGeeks and stay ahead of the curve.

Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated : 29 Aug, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials