class Test:
alive = True
def __init__(self,name,age):
self.name = name
self.age = age
def calling(self):
return f'hello!! {self.name}. You are {self.age}. Are you alive {self.alive}'
class Test_child(Test):
pass
test1 = Test('Paul',19)
child1 = Test_child('John',27)
child1.calling()
child1.name = 'Adam'
child1.calling()
为什么我的程序只执行类中的最后一个调用方法。为什么两者都不呢?
并不是只调用了最后一个方法。我认为缺少打印报表。例如:
child1.calling()
进入
print(child1.calling())
我认为你有这个问题,因为你在jupyter笔记本或谷歌拼贴画中执行代码,不是吗?