Comparison Operators In Python

Comparison operations are used to compare variables such as integers and strings. There are different comparison operators used by programmers in their programs. In Python following comparison operators have been used.

1.     Equal-to value Operator (==)

Equal-to operator (==) is used to compare two values. It compares the left operand value with the right operand and if both are the same then it will return True otherwise False. Example: a == 10.

2.    Not-equal-to Operator (! =)

Not-equal-to operator (==) is used to compare two values. It compares the left operand value with the right operand and if the left operand values are Not Equal to the right operand, it will return True otherwise False. Example: a != 25.

.     Less-than or equal-to Operator(<=)

Less-than or equal-to operator (>=) is used to compare two conditions that the left operand value is less than or equal to the right

operand. If one of the conditions becomes true, it will return true otherwise it will return False. Example: a<=20.

  Greater-than or equal-to Operator(>=)

Greater-than or equal-to operator (>=) is used to compare conditions that the left operand value is greater than or equal to the right

operand. If one of the conditions becomes true, it will return true otherwise it will return False. Example: a>=20.

 Greater-than Operator(>)

Greater-than Operator (>) is used to compare left operand value is greater than right operand, if the condition is true it will

return True otherwise False. Example: a>15.

Less-than Operator(<)

Less-than Operator (<) is used to compare left operand value is less than right operand, if the condition is true it will return True

otherwise False. Example: a<15.


# ==
a = 2
b = 2
if a == b:
    print("True")
else:
    print("False")

# !=
a = 2
b = 3.2
if a != b:
    print("True")
else:
    print("False")
    
# <=
a = 2
b = 3.2
if a <= b:
    print("True")
else:
    print("False")
    
# >=
a = 2
b = 3.2
if a >= b:
    print("True")
else:
    print("False")

# <
a = 2
b = 3.2
if a < b:
    print("True")
else:
    print("False")
    
# >
a = 2
b = 3.2
if a > b:
    print("True")
else:
    print("False")
Github:
https://github.com/asadraza825/python/blob/master/comparison_operators.ipynb

Tags: Python, Python Programming,  Python Comparison operators, Comparison Operators
Next Post Previous Post
No Comment
Add Comment
comment url