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