class Word(object):
def __init__(self, text):
self.text = text
def __len__(self):
return len(self.text)
def __str__(self):
return 'Als Zeichenfolge lesen'
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)#Als Zeichenfolge lesen
print(w + w2)#testtest2
print(w == w2)#FAlse
Recommended Posts