4. Comparison Operators

  • These operators are used to compare the values of operands on either side of this type of operators. These operators return true or false Boolean values. They return true if the condition is satisfied otherwise the return false.

Operator

Usage

Description

Example

==

a==b

Returns True if either side of operands of the operator are equals to each other otherwise returns False

a=3, b=3 then a==b (returns True)

!=

a!=b

Returns True if either side of operands of the operator are equals to each other otherwise returns False

a=3, b=3 then a!=b (returns False)

a>b

Returns True if the left operand is greater than the right operand otherwise returns False

a=8, b=3 then a>b (returns True)

a<b

Returns True if the left operand is lesser than the right operand otherwise returns False

a=8, b=3 then a<b (returns True)

>=

a>=b

Returns True if the left operand is greater than or equals the right operand otherwise returns False

a=8, b=3 then a>=b (returns True)

<=

a<=b

Returns True if the left operand is lesser than the right operand otherwise returns False

a=8, b=3 then a<=b (returns False)


The following video resource provides you many examples for comparison operators in Python.

"# 22 Comparison Operators in Python" by , iTech e-Learn is licensed under CC BY-SA 3.0