What is Comparison Operator in Python?


In comparison operators in Python, the values on both sides of the operand are compared and the relationship between them is determined. A relational operator is another name for it.

Python has a number of comparison operators ( ==, != , <>, >,<=, etc.).

Example of Python Comparison Operator

We will compare the value of x to the value of y and report the result as true or false for comparison operators. 

As an example, our value of x = 4 is less than y = 5. Thus when we display the value as x>y, it really compares the values of x and y and returns false since the comparison is incorrect.

x = 4

y = 5

print(('x > y  is',x>y))

Output

(‘x > y is’, False)

You can also use other comparison operators. (x < y, x==y, x!=y, etc.)


Leave a Reply

Your email address will not be published. Required fields are marked *