python之super()函数

python的构造器奇特, 使用魔方. 构造器内对基类对象的初始化同样也很奇特, 奇特到没有半点优雅!

在构造器中使用super(class, instance)返回super对象,然后再调用某个方法, 这样super对象就自动将继承链上所有的super实例迭代地调用该方法.示例:

>>> class A:
...     def __init__(self):
...             self.name='shit'
...
>>> class B(A):
...     def __init__(self):
...             super(B,self).__init__()
...             self.greet=self.name+' your shit!'
...
>>> b=B()
>>> b.greet
'shit your shit!'

python之super()函数的更多相关文章

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

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

  2. Python中super函数的用法

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

  3. python的super函数学习

    一.为什么要用super? 在Python 2.2以前,通常的做法: class A: def __init__(self): print "enter A" print &quo ...

  4. Python关于super()函数的理解

    看下面的例子: class A: def __init__(self, name): self.name = name def bb(self): print('没事就爱瞎BB') class B(A ...

  5. python 中 super函数的使用

    转载地址:http://python.jobbole.com/86787/ 1.简单的使用 在类的继承中,如果重定义某个方法,该方法会覆盖父类的同名方法,但有时,我们希望能同时实现父类的功能,这时,我 ...

  6. python中super函数的参考

    https://rhettinger.wordpress.com/2011/05/26/super-considered-super/ http://wiki.jikexueyuan.com/proj ...

  7. super函数

    Python面向对象中super用法与MRO机制:https://www.cnblogs.com/chenhuabin/p/10058594.html python 中 super函数的使用:http ...

  8. Python内置函数(30)——super

    英文文档: super([type[, object-or-type]]) Return a proxy object that delegates method calls to a parent ...

  9. Python内置函数(63)——super

    英文文档: super([type[, object-or-type]]) Return a proxy object that delegates method calls to a parent ...

随机推荐

  1. 【转】驱动中的类class和节点

    原文出处:http://blog.chinaunix.net/uid-23036581-id-2230558.html 一个类是一个设备的高级视图, 它抽象出低级的实现细节. 驱动可以见到一个SCSI ...

  2. vs克隆新建团队项目

    团队资源——克隆,完成后打开: 在解决方案资源中,添加——新建项目——web——ASP.NET web应用程序——空的,并将其设为启动项目:

  3. poj 3981 字符串替换

    字符串替换 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10871   Accepted: 5100 Descriptio ...

  4. hdu3336

    Count the string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  5. C#导出DataGridView到Excel

    public class ExcelHelper { private static object missing = Type.Missing; #region ================导出= ...

  6. js验证连续两位数字递增或递减和连续三位数字相同

    <!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8" ...

  7. CSS - 实现文字显示过长时用省略

    一.添加-文字显示超出范围时隐藏属性 overflow:hidden; 二.添加-超出文字省略号属性 text-overflow:ellipsis; 三.添加-文字不换行属性 white-space: ...

  8. C# 短信猫(SMS cat) 操作源码开发经验

    我曾经开发的某项目需要使用短信猫模块,要求使用C#编程操作.能独立使用的动态链接库之一就是网上流传的sms.dll,但它的功能较少,不能满足需求,鉴于一时找不到合适的完整代码,我深入研究了短信协议,借 ...

  9. 关于SVN下载代码和Android Studio里面导入别人代码build tools不一致问题总结

    项目build tools的sdk我没有 网络问题没法下载. 解决问题 方法 1.下载对应的SDK.需要VPN,或者FQ 2.将bulid.gradle的内容用下面的内容替换 // Top-level ...

  10. VHDL操作运算符的优先级顺序