DEV Community

Cover image for Comparison Operators in python
Aswin Barath
Aswin Barath

Posted on • Edited on

3 3 1 1 1

Comparison Operators in python

So, basically, comparison operators are used to comparing two values that are numbers.

If we level up to be geeky, comparison operators can also be used to compare other data types.

Now, let's start with equality checks and I hope you like spider-man movies.

== Equal comparison operator

Alt Text
Output:

False
True
Enter fullscreen mode Exit fullscreen mode

!= Not Equal comparison operator

Alt Text
Output:

True
False
Enter fullscreen mode Exit fullscreen mode

Alright, I'm sure that you are aware of how to use other operators to compare two number values, right?
OK, now's the time to level up to be geeky.

For the rest of the operators let us compare the letters from the Alphabet.
Wait, what?!
You heard me right!

Let me explain it at the end of this post.

> Greater than comparison operator

Alt Text
Output:

False
True
False
Enter fullscreen mode Exit fullscreen mode

< Less than comparison operator

Alt Text
Output:

True
True
False
Enter fullscreen mode Exit fullscreen mode

>= Greater than or equal to comparison operator

Alt Text
Output:

False
True
True
Enter fullscreen mode Exit fullscreen mode

<= Less than or equal to comparison operator

Alt Text
Output:

False
True
True
Enter fullscreen mode Exit fullscreen mode

Here's the answer for the above craziness.

When we compare two letters (or characters), it gets converted into ASCII code. You can check the link where the table contains 'DEC' (Decimal values) for the characters from Alphabet.

Now that the characters are converted into ASCII code, which is nothing but numbers and we are back to square one.
That is, we can compare the values as numbers and return True or false.

Best Resources

Who Am I?

I’m Aswin Barath, a Software Engineering Nerd who loves building Web Applications, now sharing my knowledge through Blogging during the busy time of my freelancing work life. Here’s the link to all of my socials categorized by platforms under one place: https://linktr.ee/AswinBarath

Thank you so much for reading my blog🙂.

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more →

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay