2024年06月02日 建站教程
如何利用Python语法实现重写父类,下面web建站小编给大家简单介绍一下具体实现代码!
具体代码如下:
class Youlike(object):
def eat(self):
print("你喜欢吃什么?")
class Food(Youlike):
def eat(self):
print("臭豆腐")
# 格式一:父类名.方法名(对象)
Youlike.eat(self)
# 格式二:super(本类名,对象).方法名()
super(Food, self).eat()
# 格式三:super()方法名()
super().eat()
food1 = Food()
food1.eat()
print(food1)
本文链接:http://so.lmcjl.com/news/5804/