为了账号安全,请及时绑定邮箱和手机立即绑定

Python中子类怎样调用父类方法?

Python中子类怎样调用父类方法?

PHP
犯罪嫌疑人X 2019-03-06 15:07:44
Python中子类怎样调用父类方法
查看完整描述

2 回答

?
幕布斯7119047

TA贡献1794条经验 获得超8个赞

子类调用父类函数有以下方法:

  1. 直接写类名调用

  2. 用 super(type, obj).method(arg)方法调用。

  3. 在类定义中调用本类的父类方法,可以直接用super().method(arg)

123456789class 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


查看完整回答
反对 回复 2019-03-27
  • 2 回答
  • 0 关注
  • 530 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信