In this tutorial, we will discuss how different relational operators can be used in Python programs.
The relational operators are also known as comparison operators, their main function is to return either a true or false based on the value of operands.
Following are the relational operators-
- >
- =
- =, =
Checks whether the left operand is greater than or equal to the right operand. 10 >= 10 it will return true
5 >= 10 it will return false.Relational Operators - Sample Program
Example
a = 5 b = 10 print[a == b] #return False print[a != b] #return True print[a = b] #return False
Relational operators are frequently used in decision making and looping statements. We will discuss about it in the future topics.
Topics You Might Like
What are the 6 relational operators in Python?
We have six of these, including and limited to- less than, greater than, less than or equal to, greater than or equal to, equal to, and not equal to. So, let's begin with the Python Comparison operators.What are the 6 relational operators?
There are six types of relational operators: equal, greater than, less than, greater than or equal to, less than or equal to, and not equal to. Each of these operators can be used to compare the values of the variables. The result of each of these operators is either true or false.What are the 4 operators in Python?
Example.Arithmetic operators..Assignment operators..Comparison operators..Logical operators..Identity operators..Membership operators..Bitwise operators..What are relational operators?
Relational operators compare numeric, character string, or logical data. The result of the comparison, either true [ 1 ] or false [ 0 ], can be used to make a decision regarding program flow [see the IF statement]. Table 1 lists the relational operators.