In Python, relational operators (also known as comparison operators) are used to compare two values. Here are six common relational operators:
-
Equal to (
==
): Checks if two values are equal.a == b
-
Not equal to (
!=
): Checks if two values are not equal.a != b
-
Greater than (
>
): Checks if the left value is greater than the right value.a > b
-
Less than (
<
): Checks if the left value is less than the right value.a < b
-
Greater than or equal to (
>=
): Checks if the left value is greater than or equal to the right value.a >= b
-
Less than or equal to (
<=
): Checks if the left value is less than or equal to the right value.a <= b
These operators return a Boolean value (True
or False
) based on the comparison.