
python子类如何才能调用父类的方法
展开全部
.直接写类名调用
2.用 super(type, obj).method(arg)方法调用。
3.在类定义中调用本类的父类方法,可以直接 super().method(arg).
在代码中调用对象的父类的方法的示例:
ob = B()super(B,ob).method(arg) #调用class B的父类class A的method。
初始化中调用父类初始化方法示例:class B(A):def __init__(self):super().__init__()
2.用 super(type, obj).method(arg)方法调用。
3.在类定义中调用本类的父类方法,可以直接 super().method(arg).
在代码中调用对象的父类的方法的示例:
ob = B()super(B,ob).method(arg) #调用class B的父类class A的method。
初始化中调用父类初始化方法示例:class B(A):def __init__(self):super().__init__()
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |