Comment est le " est " de mots clés mis en œuvre en Python?

... la is mot-clé qui peut être utilisé pour l'égalité dans les cordes.

>>> s = 'str'
>>> s is 'str'
True
>>> s is 'st'
False

J'ai essayé les deux __is__() et __eq__() mais ils n'ont pas de travail.

>>> class MyString:
...   def __init__(self):
...     self.s = 'string'
...   def __is__(self, s):
...     return self.s == s
...
>>>
>>>
>>> m = MyString()
>>> m is 'ss'
False
>>> m is 'string' # <--- Expected to work
False
>>>
>>> class MyString:
...   def __init__(self):
...     self.s = 'string'
...   def __eq__(self, s):
...     return self.s == s
...
>>>
>>> m = MyString()
>>> m is 'ss'
False
>>> m is 'string' # <--- Expected to work, but again failed
False
>>>
InformationsquelleAutor Srikanth | 2010-06-07