python中super函数的使用示例
更新:HHH   时间:2023-1-7


这篇文章主要介绍python中super函数的使用示例,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

1、super()

主要用于类的多继承中,用来查找并调用父类的方法。

当父类的名字修改后,子类中相应的名字也要进行修改。为了避免该问题,可通过super()解决。

2、super函数语法

super(type,object-or-type)

3、参数

type — 类,一般是类名;

object-or-type — 类,一般是 self;

4、返回值:无

5、使用

class parent:
    def fun1(self,message):
        print(message)
class child(parent):
    def fun2(self,message):
        super(child,self).fun1(message)
 
>>> child().fun2('hello')
hello

以上是“python中super函数的使用示例”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注天达云行业资讯频道!

返回编程语言教程...