Comparison assignment#

Comparison operators are used to compare two values or expressions and return a Boolean value (True or False) based on the comparison result.

Operation

Operator

Examples

Is Equal To

==

10 == 8 is False

Not Equal To

!=

10 != 8 is True

Greater Than

>

10 > 8 is True

Less Than

<

10 < 8 is False

Greater Than or Equal To

>=

10 >= 8 is True

Less Than or Equal To

<=

10 <= 8 is False

Examples

# Comparison of two numbers
# equal to
test_comparison = 10 == 8
print(test_comparison)
False
# not equal to
test_comparison = 10 != 8
print(test_comparison)
True
# greater than - it verifies if 10 is greater than 8
test_comparison = 10 > 8
print(test_comparison)
True
# less than
test_comparison = 10 < 8
print(test_comparison)
False
# greater than or equal to
test_comparison = 10 >= 8
print(test_comparison)
True
# less than or equal to
test_comparison = 10 <= 8
print(test_comparison)
False