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

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


犯罪嫌疑人X
浏览 531回答 2
2回答

幕布斯7119047

子类调用父类函数有以下方法:直接写类名调用用 super(type, obj).method(arg)方法调用。在类定义中调用本类的父类方法,可以直接用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
打开App,查看更多内容
随时随地看视频慕课网APP