*80*

# Relational Operators in Python

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-

- >
- <
- ==
- !=
- >=
- <=

Letâ€™s start with the first one-

## 1. Greater or less than (>, <)

The program given below illustrates how it can be done-

**Output:**

The sum of a and b is 30 True False False True

**Explanation-**

Itâ€™s time to have a look at the explanation of the above program-

- In the first step, we have initialized the values of the variables of a and b is 20 and 10.
- In the next step, we have calculated the sum of a and b.
- Finally, we printed the values evaluated based on greater than or less than.
- If a is greater than b, it gives the output as â€˜Trueâ€™, else it gives â€˜Falseâ€™ and vice versa.
- On executing the given program, the desired output is displayed.

## 2. Equals to (==)

The equals to â€˜==â€™ operator return a True value if values stored in two variables are the same.

The following program illustrates its usage

**Output:**

The sum of a and b is 30 The difference of d and b is 20 True False True True

**Explanation-**

Letâ€™s understand what happened in the above program-

- In the first step, we have initialized the values of the variables of a and b is 20 and 10.
- In the next step, we have calculated the sum of a and b and the difference of d and b.
- Finally, we printed the values evaluated based on greater than, less than, and equals to.
- If c is equal to d, it gives the output as â€˜Trueâ€™, else it gives â€˜Falseâ€™ and vice versa.
- On executing the given program, the desired output is displayed.

## 3. Not Equal to (!=)

The not equals to â€˜!=â€™ operator returns a True value if values stored in two variables are different.

Consider the program given below-

**Output:**

The sum of a and b is 30 The difference of d and b is 20 True True False True

**Explanation-**

Letâ€™s have a glance at the explanation of the above program-

- In the first step, we have initialized the values of the variables of a and b is 20 and 10.
- In the next step, we have calculated the sum of a and b and the difference of d and b.
- Finally, we printed the values evaluated based on greater than, less than, equals to, and not equals to.
- If a is not equal to
**b**, it gives the output as â€˜Trueâ€™, else it gives â€˜Falseâ€™ and vice versa. - On executing the given program, the desired output is displayed.

Finally, we will discuss the last relational operator which is greater than equal to or less than equal to.

## 4. Greater than or less than equal to (>=, <=)

The greater than equal to returns â€˜Trueâ€™ if the value in any of the two variables is greater than or equal to the second one.

The â€˜lesser than equal toâ€™ works in a similar way.

Let us see how it can be used in a Python program,

**Output:**

The sum of a and b is 30 The difference of d and b is 20 True True True True

**Explanation-**

The program given below illustrates how it can be done-

- In the first step, we have initialized the values of the variables of a and b is 20 and 10.
- In the next step, we have calculated the sum of a and b and the difference of d and b.
- Finally, we printed the values evaluated based on greater than, less than, equals to, not equals to, greater than equal to, and less than equal to.
- If a is greater than equal to b, it gives the output as â€˜Trueâ€™, else it gives â€˜Falseâ€™ and vice versa.
- On executing the given program, the desired output is displayed.

## Conclusion

In this tutorial, we learned how relational operators can be used in a Python program.