... le is
qui peut être utilisé pour l'égalité dans les chaînes de caractères.
>>> s = 'str'
>>> s is 'str'
True
>>> s is 'st'
False
J'ai essayé les deux __is__()
et __eq__()
mais ça n'a pas marché.
>>> 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
>>>