class FirstClass:
def setdata(self,value):
self.data = value
def display(self):
print(self.data)
x = FirstClass()
y = FirstClass()
x.setdata('King Arthur')
y.setdata(3.14)
x.display()
y.display()
x.data = 'New Data'
x.display()
class SecondClass(FirstClass):
def display(self):
print('current value = "%s"' % (self.data))
z = SecondClass()
z.setdata(43)
z.display()
class ThirdClass(FirstClass):
def _init_(self,value):
self.data = value
def _add_(self,other):
return ThirdClass(self.data + other)
def _str_(self):
return '[ThirdClass: %s]' % self.data
def mul(self,other):
self.data *= other
b = ThirdClass('abc')
b.display()
我是照着书上敲的代码页报以下错:
b = ThirdClass('abc')
TypeError: object.__new__() takes no parameters
慕码人2483693
有只小跳蛙
相关分类