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. 给定数组a[N]构造数组b[N]

    转自:http://blog.csdn.net/wumuzi520/article/details/7841280 给定一个数组a[N],我们希望构造数组b [N], 其中b[j]=a[0]*a[1] ...

  2. 【转】ASP.NET 高效分页存储过程

    代码 Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-- ...

  3. Java计算机网络

    计算机网络: 分布在不同的地域的计算机通过外接设备(路由器),实现共享和数据传输网络编程:网络编程主要是用来解决计算机和计算机之间的数据传输网络编程:不需要基于HTML就可以达到数据之间的传输,比如Q ...

  4. Table of Contents - MongoDB

    Getting Started Installation Installing MongoDB on Windows Installing MongoDB on Linux Introduction ...

  5. JS正则表达式简单总结

    正则表达式定义 JavaScript中的正则表达式用RegExp 对象表示,可以使用RegExp ()构造函数来创建RegExp对象,不过RegExp 对象更多的是通过一种特殊的直接量愈发来创建. 例 ...

  6. Part 14 ng hide and ng show in AngularJS

    ng-hide and ng-show directives are used to control the visibility of the HTML elements. Let us under ...

  7. Part 99 Lambda expression in c#

    class Program { static void Main(string[] args) { List<Person> persons = new List<Person> ...

  8. 删除HT和CAS角色与扩展在另一台服务器

      背景:原先使用三合一方式部署的架构,如今不再满足企业需求,因此需要将原来的一台服务器多角色的拆分开,即由原来CAS.HT.MBX角色集一台服务器的分成两台服务器来部署,此架构为MBX角色单独部署在 ...

  9. XibDemo

    ////  MyviewViewController.h//  XibDemo////  Created by hehe on 15/9/21.//  Copyright (c) 2015年 wang ...

  10. WCF之消息模式

    请求/响应:所有操作的默认行为,在WSDL中表现为Input/Output元素. One_Way. 在WSDL中只有Input,没有回应(Output),所以没有异常报告. 单向操作只会在发出调用的瞬 ...