We can compare two strings in python by comparison operators. There are many comparison operators like ‘==’, ‘!=’, ‘>’, ‘<‘, etc.
String comparison in python takes place character by character.
- == – It checks whether two strings are equal.
- != – It checks whether two strings are not equal.
- > – It checks whether string on the left is greater than the right.
- < – It checks whether the string on the right is greater than the left.
n="python" a="pythonpoint" print(n==a)
output - False
We can do case-sensitive comparisons of strings also. To do case-sensitive comparison python offer special functions isupper() and islower().
s="PYTHON" print(s.isupper()) print(s.islower())