Python中子类怎样调用父类方法
2 回答

幕布斯7119047
TA贡献1794条经验 获得超8个赞
子类调用父类函数有以下方法:
直接写类名调用
用 super(type, obj).method(arg)方法调用。
在类定义中调用本类的父类方法,可以直接用super().method(arg)
123456789 | class A: def method( self , arg): pass class B(A): def method( self , arg): # A.method(self,arg) # 1 # super(B, self).method(arg) # 2 super ().method(arg) # 3 |
- 2 回答
- 0 关注
- 530 浏览
添加回答
举报
0/150
提交
取消