【发布时间】:2018-04-02 20:03:36
【问题描述】:
我有一个名为 Cyborg 的类,它继承自另外两个类:Human 和 Robot。 假设两个父母有自己的方法 Talk(),我可以从 Cyborg 孩子调用这两个方法吗?例如:
class Cyborg(Human, Robot):
def Talk(self):
human_properties = Human.Talk()
robot_properties = Robot.Talk()
return human_properties + robot_properties
super() 方法不能解决这个问题。
【问题讨论】:
-
你能给出
Robot和Human的(最小)定义吗? -
在使用类调用方法时必须显式传递
self:分别为Human.talk(self)和Robot.talk(self)。
标签: python python-3.x multiple-inheritance