python
class Word(object):
def __init__(self, text):
self.text = text
def __str__(self):
return 'texttxet'
def __len__(self):
return len(self.text)
def __add__(self, word):
return self.text.lower() + word.text.lower()
def __eq__(self, word):
return self.text.lower == word.text.lower()
w = Word('aaaaaaaaaa')
w2 = Word('bbbbbbbbbbbbb')
print(w)
print(len(w))
print(w + w2)
print(w == w2)
Ausführungsergebnis
texttxet
10
aaaaaaaaaabbbbbbbbbbbbb
False
Recommended Posts