选项A:
class Mammal(object):
def __init__(self, name):
self.name = name
def __str__(self):
return str(self.name)
class Human(Mammal):
def __init__(self, name):
self.name = name
me = Human("John")
print(me)
选项 B:
class Mammal(object):
def __init__(self, name):
self.name = name
def __str__(self):
return str(self.name)
class Human(Mammal):
def __init__(self, name):
super(Human, self).__init__(name)
me = Human("John")
print(me)
两种选择都返回相同的结果,但是有人可以解释将名称分配给子类(人类)和父类(哺乳动物)之间的区别吗?这两种选择之间有更好的选择吗?
非常感谢!