Comparison Operators in Python (With Examples):

comparison-operator-in-python-with-examples

Wanna know “What is a comparison operator in python” basically comparison operators are used to compare or analysing two values even if they have the same values.

If you are new then visit the previous module to learn about Python Fundamentals to get an exact understanding of this module. So, let’s start without wasting time

Here are some possible comparison operators that can be used in Python:

  • Equality (==)
  • Non Equality (!=)
  • Greater than (>)
  • Less than (<)
  • Greater than or equal to (>=)
  • Less than or equal to (<=)

Equality in Python:

To prove one element to another we use a double equal(==) sign.

x=5
y=5
if x == y:
    print("x is equal to y")

If x and y are not equal so the output will be False.

Non Equality in Python:

For non-equality, we use the (!=) operator.

x=5
y=6
if x != y:
    print("x is not equal to y")

Greater Operator in Python:

in Python, this (<) is used as a greater operator.

x=10
y=5
if x > y:
    print("x is greater then y")

Less than Operator in Python:

In Python, we use this (<) as a less-than operator.

x=5
y=10
if x < y:
    print("x  is less than y")

Greater than or equal to:

To determine whether a value is greater than or equal to another we use this (>=) operator in python.

x=15
y=9
if x >= y:
    print("x is greater than or equal to y")

Less than or equal to:

For less than or equal to we use (<=) operator.


x=20
y=20
if x <= y:
    print("x is less than or equal to y")

Here are all about python comparison operators. in this tutorial, we learn how to use these operators in python.

So, in the next tutorial, we are going to learn about Logical Operators. So, make sure to subscribe to us to learn python in easy way.


Discover more from Python Mania

Subscribe to get the latest posts sent to your email.

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments

Related Articles:

Recent Articles:

0
Would love your thoughts, please comment.x
()
x

Discover more from Python Mania

Subscribe now to keep reading and get access to the full archive.

Continue reading