Python Strings Comparison
kodingwindow@kw:~$ python3
...
>>> s1="Koding"
>>> s2="window"
>>> s3=s1+s2
>>> s3
'Kodingwindow'

>>> s1==s2
False

>>> s1!=s2
True

>>> s1>s2
False

>>> s1<s2
True

>>> s3>=s3
True

>>> s3<=s3
True

>>> s3==s3
True

>>> s3!=s3
False

>>> s3 is s3
True

>>> s3 is not s3
False
Strings are immutable (one can't alter the contents of the object)
>>> s1="Koding"
>>> s2="window"
>>> id(s1)
140269279579312

>>> id(s2)
140269256679152

>>> s1=s2
>>> id(s1)
140269256679152

>>> id(s2)
140269256679152

>>> s2[0]="W"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'str' object does not support item assignment
Advertisement