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

</>
Copy
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

</>
Copy
a = 4
b = 4

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

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

</>
Copy
a = 'apple'
b = 'banana'

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

Output

a and b are not equal.

Conclusion

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