0
我努力學習Python中的超級實現,我已經嘗試了SO各種幫助線程,但我沒能實現以下代碼:訪問父類的方法錯誤
class Person:
def __init__(self, first, last, age):
self.firstname = first
self.lastname = last
self.age = age
def __str__(self):
return self.firstname + " " + self.lastname + ", " + str(self.age)
class Employee(Person):
def __init__(self, first, last, age, staffnum):
super(Employee, self).__init__(first, last, age)
self.staffnumber = staffnum
def __str__(self):
return super(Employee, self).__str__() + ", " + self.staffnumber
x = Person("Marge", "Simpson", 36)
y = Employee("Homer", "Simpson", 28, "1007")
print(x)
print(y)
有什麼不對這種語法在上面的代碼?
return super(Employee, self).__str__() + ", " + self.staffnumber