- In python, the comparison operator is used to compare one value with the other value.
- A comparison operator can be known as a relational operator as it shows the relation between the two values.
- It returns the result in bool type i.e True or False.
- It is applicable for string, boolean, numbers(int type).
- In the comparison, if one comparison is true then the result will be true, and if one comparison is false all the results will be false.
- Eg; 10<20>30, the result is false.
- We have six different types of comparison operators/ relational operators
- == Equal to.
- != not equal to.
- > Greater than.
- < Less than.
- >= Greater than or Equal to.
- <= Less than or equal to.
- Equal to(==): If the values on both sides of operands are equal then the result is true, else false.
Example: write a python code for comparison/relational operator using equal to the operator for string type.
Example: write a python program using the not equal operator for an int data type.
- print("x not equal to y")
Example: write a python program using less than operator for string type.
Example: write a python program for string data type using greater than the operator.
Example: write a python code for int data type using less than or equal to operator.
- print("x less than or equal to y")