首页 > 解决方案 > function .. 接受 0 个位置参数,但给出了 1 个

问题描述

我是 Python 新手,我想练习一个父类和派生类。我想使用 super 将父函数调用到子类。但是我遇到了一些错误。代码是

class First:
    def my_func():
        print('first')

class Second(First):
    def my_func1():
        super().my_func()
        print('second')

obj = Second()
obj.my_func1()

标签: pythonoop

解决方案


class First:
    def my_func(self):
        print('first')

class Second(First):
    def my_func1(self):
        super().my_func()
        print('second')

obj = Second()
obj.my_func1()

推荐阅读