p y t h o n 中 的 s u p e r 函 数 python中的super函数 python中的super函数
super() 函数是用于调用父类(超类)的一个方法。
class A:
def add(self, x):
y = x+1
print(y)
class B(A):
def add(self, x):
super().add(x)
b = B()
b.add(2)
# j结果:3
super() 函数是用于调用父类(超类)的一个方法。
class A:
def add(self, x):
y = x+1
print(y)
class B(A):
def add(self, x):
super().add(x)
b = B()
b.add(2)
# j结果:3
经常有朋友问,学 Python 面向对象时,翻阅别人代码,会发现一个 super() 函数,那这个函数的作用到底是什么?
1)class类包含:类的属性:类中所涉及的变量类的方法:类中函数2) __init函数(方法)1、带有两个下划线开头的函数是声明该属性为私有,不能在类地外部被使用或直接访问。
举报文章
请选择举报类型
补充说明
0/200
上传截图
格式支持JPEG/PNG/JPG,图片不超过1.9M