Python Equal Operator

In Python, Comparison Equal Operator takes two operands and returns a boolean value of True if both the operands are equal, else it returns False.

Syntax

The syntax to check if two values: `a` and `b` are equal using Equal Operator is

`a == b`

The above expression returns a boolean value.

Examples

1. Check if two numbers are equal

In the following program, we take two numbers: `a`, `b`; and check if these two numbers are equal.

main.py

```a = 4
b = 4

if a == b :
print('a and b are equal.')
else :
print('a and b are not equal.')```
Try Online

Output

`a and b are equal.`

2. Check if two strings are equal

In the following program, we take two string values: `a`, `b`; and check if these two strings are equal.

main.py

```a = 'apple'
b = 'banana'

if a == b :
print('a and b are equal.')
else :
print('a and b are not equal.')```
Try Online

Output

`a and b are not equal.`

Conclusion

In this Python Tutorial, we learned about Comparison Equal Operator, its syntax, and usage, with examples.