Tag Archives: compare strings in Python

How to compare strings in Python

Let’s say you want to compare two string to see if they have the same value. You can do it using the comparison operator is equal to which is represented by == (two equal signs).

>>> s1 = 'Dan'
>>> s2 = 'Dumitrache'
>>> if s1 == s2:
... print('Strings are equal!')
... else:
... print('Strings are not equal!')
Strings are not equal!

Continue reading