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
False
True
!=
Not Equal comparison operator
True
False
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
False
True
False
<
Less than comparison operator
True
True
False
>=
Greater than or equal to comparison operator
False
True
True
<=
Less than or equal to comparison operator
False
True
True
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
Python Blog Series : A Blog series where I will be learning and sharing my knowledge on each of the above topics.
Learn Python for Free, Get Hired, and (maybe) Change the World! : A detailed roadmap blog by Jayson Lennon (a Senior Software Engineer) with links to free resources.
Zero To Mastery Course - Complete Python Developer : A comprehensive course by Andrei Neagoie (a Senior Developer) that covers all of the above topics.
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🙂.
Top comments (0)