In computer programming, relational operators are used to compare two operands. These comparisons yield a boolean value based on whether a statement is true or false. This is similar to how an if statement works when it evaluates its conditions.
Table of Contents
In computer programming, relational operators are used to compare two operands. These comparisons yield a boolean value based on whether a statement is true or false. This is similar to how an if statement works when it evaluates its conditions.
Types of Relational Operators
There are six types of relational or comparison operators in python language.
- Equal to (==)
- Greater than (>)
- Less than (<)
- Greater than or equal to (>=)
- Less than or equal to (<=)
- Not equal to (!=)
i) Equal to (==)
The symbol of equal to in python language is ==.
num_1 = 43
num_2 = 36
print(num_1==num_2)
Output:
False
ii) Greater than (>)
The symbol of greater than in python language is >.
num_1 = 43
num_2 = 36
print(num_1>num_2)
Output:
True
iii) Less than (<)
The symbol of less than in python language is <.
num_1 = 43
num_2 = 36
print(num_1<num_2)
Output:
False
iv) Greater than or equal to (>=)
The symbol of greater than or equal to in python language is >=.
num_1 = 43
num_2 = 36
print(num_1>=num_2)
Output:
True
v) Less than or equal to (<=)
The symbol of less than or equal to in python language is <=.
num_1 = 43
num_2 = 36
print(num_1<=num_2)
Output:
False
vi) Not equal to (!=)
The symbol of not equal to in python language is !=.
num_1 = 43
num_2 = 36
print(num_1!=num_2)
Output:
True
Read the full details of Python Operators in this article: