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.

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:

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: