What are Relational Operators in Python?

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.
| Operator | Name | Description | Syntax |
|---|---|---|---|
| == | Equal To | Equal to operator returns True if the first operand is equal to the second operand. Else, it returns False. | operand1 == operand2 |
| != | Not Equal To | Not Equal to operator returns True if the first operand is not equal to the second operand. Else, it returns False. | operand1 != operand2 |
| > | Greater Than | Greater Than operator returns True if the first operand is greater than the second operand. Else, it returns False. | operand1 > operand2 |
| < | Less Than | Less Than operator returns True if the first operand is lesser than the second. Else, it returns False. | operand1 < operand2 |
| >= | Greater Than or Equal To | Greater 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 To | Less 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
Modern Software and AI Engineering Program
Master full-stack development with AI integration
+1000 moreModern Data Science and ML with specialisation in AI
Advanced data science techniques with AI specialization
+1000 moreAdvanced AIML with Specialisation in Agentic AI
Deep dive into AIML with focus on Agentic systems
+1000 moreDevOps, Cloud & AI Platform Engineering
Build and manage AI-powered cloud infrastructure
+1000 moreAI Engineering Advanced Certification by IIT-Roorkee
Premier AI engineering certification from IIT-Roorkee
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
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(<=).