class Word(object):
    def __init__(self, text):
        self.text = text
    def __len__(self):
        return len(self.text)
    def __str__(self):
        return 'Lire comme une chaîne'
    def __add__(self, other):
        return self.text + other.text
    def __eq__(self, other):
        return self.text == other.text
w = Word('test')
w2 = Word('test2')
print(len(w))#4
print(w)#Lire comme une chaîne
print(w + w2)#testtest2
print(w == w2)#FAlse
Recommended Posts