普通继承

class FooParent(object):
def __init__(self):
self.parent = 'I\'m the parent.'
print 'Parent' def bar(self, message):
print message, 'from Parent' class FooChild(FooParent):
def __init__(self):
FooParent.__init__(self)
print 'Child' def bar(self, message):
FooParent.bar(self, message)
print 'Child bar function.'
print self.parent if __name__ == '__main__':
foochild = FooChild()
foochild.bar('Hello World!')
# output
Parent
Child
Hello World! from Parent
Child bar function.
I'm the parent.

super继承

class FooParent(object):
def __init__(self):
self.parent = 'I\'m the parent.'
print 'Parent' def bar(self, message):
print message, 'from Parent' class FooChild(FooParent):
def __init__(self):
super(FooChild, self).__init__()
print 'Child' def bar(self, message):
super(FooChild, self).bar(message)
print 'Child bar function.'
print self.parent if __name__ == '__main__':
foochild = FooChild()
foochild.bar('Hello World!')
# output
Parent
Child
Hello World! from Parent
Child bar function.
I'm the parent.

python super用法的更多相关文章

  1. [python] super() 用法

    问题的发现与提出 在Python类的方法(method)中,要调用父类的某个方法,在Python 2.2以前,通常的写法如下: class A: def __init__(self): print & ...

  2. Python中的super()用法

    Python中对象方法的定义很怪异,第一个参数一般都命名为self(相当于其它语言的this,比如:C#),用于传递对象本身,而在调用的时候则不 必显式传递,系统会自动传递. 今天我们介绍的主角是su ...

  3. python super()函数

    super()函数是用来调用父类(超类)的一个方法 super()的语法: python 2 的用法: super(Class, self).xxx  # class是子类的名称 class A(ob ...

  4. Python ---- super()使用

    Python ---- super() 我们经常在类的继承当中使用super(), 来调用父类中的方法.例如下面: 1 2 3 4 5 6 7 8 9 10 11 12 13 class A:     ...

  5. Python高级用法总结

    Python很棒,它有很多高级用法值得细细思索,学习使用.本文将根据日常使用,总结介绍Python的一组高级特性,包括:列表推导式.迭代器和生成器.装饰器. 列表推导(list comprehensi ...

  6. python argparse用法总结

    转:python argparse用法总结 1. argparse介绍 argparse是python的一个命令行解析包,非常适合用来编写可读性非常好的程序. 2. 基本用法 prog.py是我在li ...

  7. Anaconda下载及安装及查看安装的Python库用法

    Anaconda下载及安装及查看安装的Python库用法 Anaconda 是一个用于科学计算的 Python 发行版,提供了包管理与环境管理的功能.Anaconda 利用 conda 来进行 pac ...

  8. python enumerate用法总结【转】

    enumerate()说明 enumerate()是python的内置函数 enumerate在字典上是枚举.列举的意思 对于一个可迭代的(iterable)/可遍历的对象(如列表.字符串),enum ...

  9. this和super用法

    1. this能分清混淆,形参名与当前对象的某个成员有相同的名字,需要明确使用this关键字来指明你要使用某个成员,使用方法是“this.成员名”. 一般以this.形参数名=形参名,代表送进来赋值的 ...

随机推荐

  1. From COM to COM 侯捷 1998.06.12

    摘要: 本文簡介 C++ Object Model 和 Component Object Model 的基本概念,並引介四本書籍: 1. Inside The C++ Object Model 2. ...

  2. 会过vip怎么赚钱?大学生,宝妈创业圈子

    会过vip怎么赚钱?是骗局吗1.如果说会过Vip不赚钱,那么一定是我们的没有时间去真心的热爱她:如果你对她如果你对它抱着一颗平和的心,认真的去分享,认真的去听一些前辈的经验,赚钱真的不是难事:2.如果 ...

  3. vue -- 异常处理集合

    1.npm run dev 运行出错,报错如下: > webpack-dev-server --inline --progress --config build/webpack.dev.conf ...

  4. 不重新编译安装php模块的方法

    如果你有下面两种经历: 如果php通过源码安装(php7),如果后来需要开启某个自带模块(例如ldap,snmp等),通常需要重新编译. 另外一些安装php模块的经历,例如redis,swoole,y ...

  5. 使用combobox下拉列表框实现省 市 县 的三级联动

    package com.hanqi.entity; //地区 public class Region { //地区id private String regionID; //地区名称 private ...

  6. SQL 日期函数转换

    1.转换函数 与date操作关系最大的就是两个转换函数:to_date(),to_char() to_date() 作用将字符类型按一定格式转化为日期类型: 具体用法:to_date('2004-11 ...

  7. 消息中间件 | 消息协议 | AMQP -- 《分布式 消息中间件实践》笔记

    04年,AMQP开放标准被开发 06年,AMQP规范被发布   基本概念     Message:与平台无相关的数据.     Publisher:向交换器发布消息的客户端应用程序     Excha ...

  8. jmeter读取本地CSV文件

    用jmeter录制考试上传成绩等脚本时,出现的问题及解决方法如下: 1.beanshell前置处理器,不能读取本地csv文件里的数据: 方法一: 在beanshell里不能直接从本地的csv文件里读取 ...

  9. 谈谈python修饰器

    前言 对python的修饰器的理解一直停留在"使用修饰器把函数注册为事件的处理程序"的层次,也是一知半解:这样拖着不是办法,索性今天好好整理一下关于python修饰器的概念及用法. ...

  10. angularJs1.x 版本中 uib-tabset 如何默认激活不同的标签页

     <uib-tabset> 默认有个active属性,根据官方文档,active的默认值是0,也就是说,默认显示索引为0的标签页,可以通过修改这个值来默认显示不同的索引的标签页. 示例: ...