如果我有课的话:
class Person(object):
'''A class with several methods that revolve around a person's Name and Age.'''
def __init__(self, name = 'Jane Doe', year = 2012):
'''The default constructor for the Person class.'''
self.n = name
self.y = year
然后这个子类:
class Instructor(Person):
'''A subclass of the Person class, overloads the constructor with a new parameter.'''
def __init__(self, name, year, degree):
Person.__init__(self, name, year)
在子类中添加新参数degree
时,如何让子类调用并使用父类构造函数来处理name
和year
,我有点迷茫。
Python建议使用
super()
。Python2:
Python3:
相关问题 更多 >
编程相关推荐