慕九州1216299
2017-02-12 18:32
class Programer(object):
hobby='Play Computer'
def __init__(self, name, age, weight):
self.name = name
self._age = age
self.__weight = weight
@classmethod
def get_hobby(cls):
return cls.hobby
@property
def get_weight(self):
return self.__weight
def self_introduction(self):
print ('My name is %s \nI an %s years old\n' %(self.name, self.age))
class BackendProgramer(Programer):
def __int__(self, name, age, weight, language):
super(BackendProgramer, self).__int__(name, age, weight)
self.language = language
if __name__ == '__main__':
programer = BackendProgramer.('Albert', 25, 80, 'Python')
print (dir(programer))
print (programer.__dir__)
print (type(programer))
print (isinstance(programer, Programer))报错信息如下:
Traceback (most recent call last):
File "C:/Users/WMY/Documents/python study/2017-2-12.py", line 26, in <module>
programer = BackendProgramer('Albert', 25, 80, 'Python')
TypeError: __init__() takes 4 positional arguments but 5 were given
不懂啥意思,只有4个参数呀,求解?
programer = BackendProgramer.('Albert', 25, 80, 'Python') 改成
programer = BackendProgramer('Albert', 25, 80, 'Python')
多了一个.
21和22行的 __int__ =======> __init__
拼写错误。。。。
个人还是比较喜欢Programer.__init__(self, age, name,weight)这种写法, 好像更直观
Python-面向对象
71226 学习 · 83 问题
相似问题