python中继承类中的默认值

python中继承类中的默认值,python,class,inheritance,Python,Class,Inheritance,我有两节课。其中父类具有一些默认值。 我希望子类继承父类的init()方法以及默认值 但是,当我试图更改可选参数的值时,我不能这样做。 例如,在下面的代码中,我无法更改year\u born的值 def get_current_age(x): return 2017-x get_age = get_current_age class Parent(): def __init__(self,name,last_name, siblings=0, year_born=1900, a

我有两节课。其中父类具有一些默认值。 我希望子类继承父类的init()方法以及默认值

但是,当我试图更改可选参数的值时,我不能这样做。 例如,在下面的代码中,我无法更改year\u born的值

def get_current_age(x):
    return 2017-x
get_age = get_current_age

class Parent():
    def __init__(self,name,last_name, siblings=0, year_born=1900, age=get_age):
        self.name = name
        self.last_name = last_name
        self.siblings = siblings
        self.year_born=year_born
        self._get_age = get_age(self.year_born)

class Child(Parent):
    def __init__(self,name,last_name, siblings=0, year_born=1900, age=get_age):
        super().__init__(name,last_name, siblings=0, year_born=1900, age=get_age)
        self.lives_with_parent= True
        self.stil_in_school= None
当我使用默认值创建父类的实例时,输出是ok的。当我使用不同的年龄值创建子实例时,它仍然采用默认值

Dad=Parent('Fyodr','Dosto')
print('Dad is' ,Dad._get_age)

kid = Child('Joseph','Dosto', year_born=2000)
print('Kid is' ,kid._get_age)

Dad is 117
Kid is 117
我不知道你是否有其他的想法来解决这个问题,或者用更好的方式来写。
非常感谢,

在儿童课上更改这一行:

super().__init__(name,last_name, siblings, year_born, age=get_age)

嗯,您调用了
super()。\uuuuu init\uuuuuuu(stuff,year\u born=1900,…)
。你期待什么?
super
的呼叫是错误的。应该是
super()。我现在看到默认值不应该出现在super()函数的调用中,而应该出现在定义中。谢谢