普通继承

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. hdu1068

    #include<stdio.h>#include<string.h>const int MAXN=1000;int map[MAXN][MAXN];int n;int lin ...

  2. MySQL 文件导入出错

    ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot exec ...

  3. mssql 递归

    --递归id往下所有内容with temp ( URE_ID, URE_PARENT_ID,URE_NAME ,URE_TYPE)as(select URE_ID, URE_PARENT_ID,URE ...

  4. webpack4下import()模块按需加载,打包按需切割模块,减少包体积,加快首页请求速度

    一:背景 因为项目功能越加越多,打包后的体积越来越大,导致首页展示的时候速度比较慢,因为要等压缩的js的包加载完毕. 首页展示的时候只需要对应的js,并不需要全部的js模块,所以这里就可以用按需加载, ...

  5. 2017-10-4 清北刷题冲刺班a.m

    P101zhx a [问题描述]你是能看到第一题的 friends 呢.——hjaHja 拥有一套时光穿梭技术,能把字符串以超越光速的速度传播,但是唯一的问题是可能会 GG.在传输的过程中,可能有四种 ...

  6. 洛谷P1441 砝码称重

    P1441 砝码称重 题目描述 现有n个砝码,重量分别为a1,a2,a3,……,an,在去掉m个砝码后,问最多能称量出多少不同的重量(不包括0). 输入输出格式 输入格式: 输入文件weight.in ...

  7. bzoj4873: [Shoi2017]寿司餐厅(最小割)

    传送门 大佬们是怎么一眼看出这是一个最大权闭合子图的……大佬好强->这里 1.把所有区间$(i,j)$看成一个点,如果权值大于0,则从$S$向他连边,容量为权值,否则从它向$T$连边,容量为权值 ...

  8. PyCharm专业版安装(2018年Windows版)

    友情提示: 本教程仅供学习交流使用,如需商业用途,强烈建议使用官方正式版.(官网正式链接为:https://www.jetbrains.com/pycharm/) 当然网上有很多其他激活教程,我看到的 ...

  9. 使用idrac远程管理卡操作安装Centos

    浏览器打开远程管理网卡地址(浏览器建议用IE,本次用的IE11,其他浏览器可能不能用) 1.首先设置虚拟控制台插件类型(推荐该为本地) 点击启动后,可能会弹窗,选择允许 2.添加镜像 创建虚拟介质 连 ...

  10. SerializeUtil

    import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.ObjectInpu ...