What are Relational Operators in Python?

Learn via video course
FREE
View all courses
Python Course for Beginners With Certification: Mastering the Essentials
Python Course for Beginners With Certification: Mastering the Essentials
by Rahul Janghu
1000
4.90
Start Learning
Python Course for Beginners With Certification: Mastering the Essentials
Python Course for Beginners With Certification: Mastering the Essentials
by Rahul Janghu
1000
4.90
Start Learning
Topics Covered

Relational Operators in python compare the operand values on either side. The relational operators in Python return a boolean value, i.e., either True or False based on the value of operands.

In simple terms, we can say that Relational operators are used for comparing the values. The relational operators are also known as Comparison Operators. There are six relational operators in Python.

Note: Relational operators in Python are the same in all versions of Python.

List of Relational Operators in Python

As we know, relational operators in python are used to compare the operand values on either side. Refer to the list below for the entire list of relational operators in python.

OperatorNameDescriptionSyntax
==Equal ToEqual to operator returns True if the first operand is equal to the second operand. Else, it returns False.operand1 == operand2
!=Not Equal ToNot Equal to operator returns True if the first operand is not equal to the second operand. Else, it returns False.operand1 != operand2
>Greater ThanGreater Than operator returns True if the first operand is greater than the second operand. Else, it returns False.operand1 > operand2
<Less ThanLess Than operator returns True if the first operand is lesser than the second. Else, it returns False.operand1 < operand2
>=Greater Than or Equal ToGreater Than or Equal To operator returns True if the first operand is greater than or equal to the second operand. Else, it returns False.operand1 >= operand2
<=Lesser Than or Equal ToLess Than or Equal To operator returns True if the first operand is less than or equal to the second operand. Else, it returns False.operand1 <= operand2

Examples of Relational Operators in Python

Let us learn each one of the relational operators in Python separately by taking examples.

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

Example 1: Program using Greater than(>) Operator

Greater than operator returns True if the first operand is greater than the second operand; otherwise, it returns False.

Refer to the example below for a better understanding:

Code:

Output:

Example 2: Program using Less than(<) Operator

Less than operator return True if the first operand is lesser than the second; otherwise, it returns False.

Refer to the example below for a better understanding:

Code:

Output:

Example 3: Program using Greater than(==) Operator

Equal to operator return True if the first operand is equal to the second operand; otherwise, it returns False.

Refer to the example below for a better understanding:

Code:

Output:

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

Example 4: Program using Not Equal To(!=) Operator

Not equal to operator return True if the first operand is not equal to the second operand; otherwise, it returns False.

Refer to the example below for a better understanding:

Code:

Output:

Example 5: Program using Greater than or Equal To(>=) Operator

Greater than or equal to operator returns True if the first operand is greater than or equal to the second operand; otherwise it returns False.

Refer to the example below for a better understanding:

Code:

Output:

Example 6: Program using Less Than or Equal To(>) Operator

Less than or equal to the operator return True if the first operand is less than or equal to the second operand; otherwise, it returns False.

Refer to the example below for a better understanding:

Code:

Output:

Conclusion

  • Relational operators in python are used to compare the operand values on either side. Relational operators in python are the same in all versions of Python.
  • The Relational operators in Python return a boolean value i.e., either True or False, based on the value of operands.
  • Relational operators are used for comparing the values. The relational operators are also known as Comparison Operators. There are six relational operators in Python.
  • The Relational operators in python are: Equal To(==), Not Equal To(!=), Greater Than(>), Less Than(<), Greater Than or Equal To(>=), and Lesser Than or Equal To(<=).

Learn More:

Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more