How to Do a String Comparison in Python | Python Tutorial
Include examples
As Python developers, we need to do a string comparison from time to time.
You can use different operators to do a string comparison.
Let’s look at some of these operators to do a string comparison in python.
Case sensitivity
Before we dive into how to do string comparisons in python.
You should know that any type of string comparison is case sensitive.
The character ‘A’ is not the same as ‘a’.
It’s because each character that is part of a string has an ASCII value.
The ASCII value stands for American Standard for Information Interchange.
When you try to do any type of comparison in python using different operators, it will compare the ASCII value of the character.
Actually, no character is compared while doing the comparison, the only thing that is compared is its ASCII value.
‘A’ has an ASCII value of 65 and ‘a’ has an ASCII value of 97. When the operator compares 65 and 97, it finds that they are not equal, and therefore returns a certain type of result.