这些是我的课程的代码:
class Employee:
def __init__(self, name, gender):
self.name = name
self.gender = gender
class Salary:
def jump(self, name, salary):
print(self.name, self.salary)
class Male(Salary, Employee):
def __init__(self, name, gender, occupation):
super(Male, self).__init__(name, gender, occupation)
self.occupation = occupation
# Separate from all classes (list of instantiated objects)
employee1 = Male("Jim", "male", "technician")
print(Male.name)
当我在创建所有类后使用代码的最后两行时,TypeError: __init__() takes 3 positional arguments but 4 were given
引用时发生错误super(Male, self).
... and employee1 = Male(
... 线条。
在“宠物”下您有:
def __init__(self, name, color):
self.name = name
self.color = color
失败者你有:
def __init__(self, name, color, owner):
super(Dog, self).__init__(name, color, owner)
在 Dog 下,给出了额外的所有者位置参数,这会导致此错误。顺便说一句,我认为super().__init__(name, color)
在 Python 3 中也同样有效
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)