Python 如何更新循环中的超级属性
我正在尝试更新类的属性,但不知道如何更新。这是我的密码:Python 如何更新循环中的超级属性,python,inheritance,Python,Inheritance,我正在尝试更新类的属性,但不知道如何更新。这是我的密码: class A(): def __init__(self,variable_that_needs_updating): super().__init__() self.var = variable_that_needs_updating def runA(self, other_var): x = 2*self.var+other_var
class A():
def __init__(self,variable_that_needs_updating):
super().__init__()
self.var = variable_that_needs_updating
def runA(self, other_var):
x = 2*self.var+other_var
return x
class B(A):
def __init__(self,initial_value_of_variable):
super().__init__(variable_that_needs_updating=initial_value_of_variable)
def runB(self, other_var):
for i in range(10):
other_var=1
#can I do something like this:
#super().variable_that_needs_updating = i
output = super().runA(other_var)
print(output)
return output
我如何让它更新“需要更新的变量”,以生成1,3,5,7,。。。对于输出?我认为您需要的是:
self.var
和self.runA(其他变量)
。子类可以访问所有父属性