1. 不带参数的多重继承

# 作者:hhh5460
# 时间:2017.07.18 class A(object):
def show_x(self):
print('A') class B(object):
def show_y(self):
print('B') class C(object):
def show_z(self):
print('C') class D(A, B, C):
pass # 测试
if __name__ == '__main__':
d = D()
d.show_x() # A
d.show_y() # B
d.show_z() # C

2. 带参数的多重继承

# 作者:hhh5460
# 时间:2017.07.18 class A(object):
def __init__(self, x=0):
self._x = x def show_x(self):
print(self._x) def show_name(self):
print('A') class B(object):
def __init__(self, y=0):
self._y = y def show_y(self):
print(self._y) def show_name(self):
print('B') class C(object):
def __init__(self, z=0):
self._z = z def show_z(self):
print(self._z) def show_name(self):
print('C') # 注意下面两类D、E,都是继承A、B、C,且A类的优先级最高。但是三条__init__语句的顺序是相反的
class D(A, B, C):
def __init__(self, x=0, y=0, z=0):
C.__init__(self, z) # init C
B.__init__(self, y) # init B
A.__init__(self, x) # init A (A最优先) class E(A, B, C):
def __init__(self, x=0, y=0, z=0):
super(E, self).__init__(x) # init A (A最优先) # 此句可简写成:super().__init__(x)
super(A, self).__init__(y) # init B
super(B, self).__init__(z) # init C # 测试
if __name__ == '__main__':
d = D(1,2,3)
d.show_x() # 1
d.show_y() # 2
d.show_z() # 3
d.show_name() # A e = E(1,2,3)
e.show_x() # 1
e.show_y() # 2
e.show_z() # 3
e.show_name() # A

python 带参数的多重继承的更多相关文章

  1. Python带参数的装饰器

    在装饰器函数里传入参数 # -*- coding: utf-8 -*- # 2017/12/2 21:38 # 这不是什么黑魔法,你只需要让包装器传递参数: def a_decorator_passi ...

  2. Python 带参数的装饰器 [2] 函数参数类型检查

    在Python中,不知道函数参数类型是一个很正常的事情,特别是在一个大项目里.我见过有些项目里,每一个函数体的前十几行都在检查参数类型,这实在是太麻烦了.而且一旦参数有改动,这部分也需要改动.下面我们 ...

  3. python带参数的类装饰器

    # -*- coding: utf-8 -*- # author:baoshan # 带参数的类装饰器(和不带参数的类装饰器有很大的不同) # 类装饰器的实现,必须实现__call__和__init_ ...

  4. Python带参数的函数装饰器

    # -*- coding: utf-8 -*- # author:baoshan # 带参数的函数装饰器 def say_hello(country): def wrapper(func): def ...

  5. python 带参数运行

    近段时间学考,又爱上了游戏.LOL  nba2k 使命召唤 哎! 因为使命召唤的原因  有时候会卡住  然后点关闭没用. 然后任务管理器打不开 所以我想写个杀掉这个程序的东西.  当然写一下是简单.但 ...

  6. python带参数装饰器使用

    # -*- coding: utf-8 -* """TensorFlow指定使用GPU工具类 author: Jill usage: 方法上加@tf_with_devic ...

  7. Python - 带参数的方法

    import math class Point: def move(self, x, y): self.x = x self.y = y def reset(self): self.move(0, 0 ...

  8. PHP带参数传值调用python脚本

    PHP主要用在服务器端做网站后台开发,有些功能用PHP来实现有点费劲或者无法实现,现在在学习python,同样是脚本语言,感觉python能做的事情PHP不一定能胜任.但是现在大部分的网站后台也是用P ...

  9. python基础之带参数装饰器和迭代器

    带参数的装饰器:就是在原装饰器外再包一层函数 def auth(driver='file'): def auth2(func): def wrapper(*args,**kwargs): name=i ...

随机推荐

  1. 安卓逆向(一)--Smali基础

    安卓逆向(一)--Smali基础 标签(空格分隔): 安卓逆向 APK的组成 文件夹 作用 asset文件夹 资源目录1:asset和res都是资源目录但有所区别,见下面说明 lib文件夹 so库存放 ...

  2. Android5.x Notification应用解析

    Notification可以让我们在获得消息的时候,在状态栏,锁屏界面来显示相应的信息,很难想象如果没有Notification,那我们的qq和微信以及其他应用没法主动通知我们,我们就需要时时的看手机 ...

  3. 在Android Studio中调用so中的方法

    本节用的so是上节用Android Studio创建的so.想在Android Studio中调用so中的方法,需要先引用so.Android Studio中引用so的方法有二种,下面开始介绍. 一 ...

  4. VMWare12虚拟机实现主客机间的文件拖拽(复制粘贴)和文件夹共享

    版本: 主机:Windows 7 64位旗舰版 虚拟机: VMWare 12 + Windows 7 64位旗舰版 VMWare pro 12 + Ubuntu16.04LTS 64位 注:由于VMW ...

  5. Sql server在使用sp_executesql @sql执行文本sql时,报错: Could not find database ID 16, name '16'. The database may be offline. Wait a few minutes and try again.

    最近在公司项目中使用exec sp_executesql @sql执行一段文本sql的时候老是报错: Could not find database ID 16, name '16'. The dat ...

  6. search文件中的config

    config文件中出现这句话时,代表该部分search应写成文件中封装好的search部分.即: var search = null;     this.search = search;     se ...

  7. mysql client之init-command

    If the server is a replication master and you want to avoid replicating the content to replication s ...

  8. 16. 窗口函数 (Window Function) 的使用

    从SQL Server 2005起,SQL Server开始支持窗口函数 (Window Function),以及到SQL Server 2012,窗口函数功能增强,目前为止支持以下几种窗口函数: 1 ...

  9. git命令:全局设置用户名邮箱配置

    1.查看git配置信息 git config --list 2.查看git用户名 git config user.name 3.查看邮箱配置 git config user.email 4.全局配置用 ...

  10. ShellCode初体验

    写在前面的话: ShellCode是一门艺术,就像围棋手门追求的“神之一手”,今天就来初探一下这让人疯狂的艺术: 零.代码0 相信手写opcode,目前很少有人干了,其实,也确实已经没有这个必要了,毕 ...