http://www.runoob.com/python/python-func-super.html

class FooParent(object): def __init__(self): self.parent = 'I\'m the parent.' print ('Parent') def bar(self,message): print ("%s from Parent" % message) class FooChild(FooParent): def __init__(self): # super(FooChild,self) 首先找到 FooChild 的父类(就是类 FooParent),然后把类B的对象 FooChild 转换为类 FooParent 的对象 super(FooChild,self).__init__() print ('Child') def bar(self,message): super(FooChild, self).bar(message) print ('Child bar fuction') print (self.parent) if __name__ == '__main__': fooChild = FooChild() fooChild.bar('HelloWorld')

执行结果:

Parent
Child
HelloWorld from Parent
Child bar fuction
I'm the parent.

super()函数的用法的更多相关文章

  1. Python中super函数的用法

    之前看python文档的时候发现许多单继承类也用了super()来申明父类,那么这样做有何意义? 从python官网文档对于super的介绍来看,其作用为返回一个代理对象作为代表调用父类或亲类方法.( ...

  2. super函数的用法

    1.创建一个类. # .创建一个类 class Bird: def __init__(self): self.hungry =True def eat(self): if self.hungry: p ...

  3. Python中的super函数,你熟吗?

    摘要:经常有朋友问,学 Python 面向对象时,翻阅别人代码,会发现一个 super() 函数,那这个函数的作用到底是什么? 本文分享自华为云社区<Python中的super函数怎么学,怎么解 ...

  4. python基础----多态与多态性、super函数用法、继承原理

    一.多态与多态性                                                                        ㈠多态: 多态指的是一类事物有多种形态, ...

  5. 面向对象编程之super内置函数的用法

    先来看一段代码: 定义一个名叫People的父类,又定义了一个叫Teacher的老师类和一个叫Student的学生类 来继承People的类,并根据这两个子类实例化出两个对象s1和t1. class ...

  6. 由Python的super()函数想到的

    python-super *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !im ...

  7. python super()函数详解

    引言: 在类的多继承使用场景中,重写父类的方法时,可能会考虑到需要重新调用父类的方法,所以super()函数就是比较使用也很必要的解决方法: 文章来源: http://www.cnblogs.com/ ...

  8. Python面试题之Super函数

    这是个高大上的函数,在python装13手册里面介绍过多使用可显得自己是高手 23333. 但其实他还是很重要的. 简单说, super函数是调用下一个父类(超类)并返回该父类实例的方法. 这里的下一 ...

  9. java中super和this用法总结

    一.this用法 概念:this是自身的一个对象,代表对象本身,可以理解为:指向对象本身的指针. this的用法在java中大致可以分为三种: 1. 普通对象的直接引用:this相当于指向当前对象本身 ...

随机推荐

  1. 每日英语:Yahoo's Rally: Made in China

    The typical honeymoon doesn't last too long before the hard work of marriage begins. And so it norma ...

  2. 快速创建各种类型的NSAttributeString和NSMutableParagraphStyle

      NSDictionary *attributes = @{ NSForegroundColorAttributeName : [ UIColorredColor ], NSFontAttribut ...

  3. 【ActiveMQ】ActiveMQ在Windows的安装,以及点对点的消息发送案例

    公司最近会用MQ对某些业务进行处理,所以,这次我下载了apache-activemq-5.12.0-bin把玩下. 基于练习方便需要,使用Windows的版本. 参考的优秀文章: activemq的几 ...

  4. C Pointer-to-Function 与 C++ Pointer-to-MemberFunction 的区别

    在看APUE Figure1.10的时候发现signal(SIGINT, sig_int)这里的sig_int直接用的函数名,但是看Thinking-in-C++ Vol.2的时候发现mem_fun( ...

  5. oozie开发注意事项

    ooziejob执行后 1. job.properties.coordinatior.xml中设置的值都是不可变的,除非将job kill掉,然后重新调度. oozie job -kill 00000 ...

  6. Toad 补充与培训 & 常用菜单

    Toad 常用菜单 新版本 toad 软件中, 比较有用的菜单 (toad10.6 版本) 下边菜单, 在日常工作中出现过的, 显示为 粉色 , 蓝色 表示次一级的重要 session 菜单 new ...

  7. 实践jQuery Easyui后本地化有感

    这个星期在忙着easyui的例子中的大部分功能的本地化.一开始给我的感觉就是把jquery easyui中的每个demo的代码粘贴复制一遍. 可是,真正在做的过程中,我才发现,我错了. 在仿写easy ...

  8. php -- ziparchive::open创建zip压缩文件

    语法: mixed ZipArchive::open ( string $filename [, int $flags ] ) 参数: filename:创建的zip的文件名 flags: ZIPAR ...

  9. 【BZOJ】1096: [ZJOI2007]仓库建设(dp+斜率优化)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1096 首先得到dp方程(我竟然自己都每推出了QAQ)$$d[i]=min\{d[j]+cost(j+ ...

  10. Think Python: How to Think Like a Computer Scientist

    Think Python: How to Think Like a Computer Scientist:http://greenteapress.com/thinkpython/html/index ...