Python多继承顺序实例分析


Posted in Python onMay 26, 2018

本文实例讲述了Python多继承顺序。分享给大家供大家参考,具体如下:

示例1:

#-*- coding:utf-8 -*-
#!python2
class A(object):
  def caller(self):
    print 'A caller'
    self.called()
  def called(self):
    print 'A called'
class B(object):
  def called(self):
    print 'B called'
class C(B,A):
  pass
if __name__ == '__main__':
  c=C()
  c.caller()

运行结果:

A caller
B  called

示例2:

#-*- coding:utf-8 -*-
#!python2
class A(object):
  def caller(self):
    print 'A caller'
    self.called()
  def called(self):
    print 'A called'
class B(object):
  def called(self):
    print 'B called'
class C(A,B):
  pass
if __name__ == '__main__':
  c=C()
  c.caller()

运行结果:

A caller
A called

希望本文所述对大家Python程序设计有所帮助。

Python 相关文章推荐
Python 第一步 hello world
Sep 25 Python
在Python中封装GObject模块进行图形化程序编程的教程
Apr 14 Python
Python使用django获取用户IP地址的方法
May 11 Python
利用Python操作消息队列RabbitMQ的方法教程
Jul 19 Python
python决策树之CART分类回归树详解
Dec 20 Python
python将txt文档每行内容循环插入数据库的方法
Dec 28 Python
Django uwsgi Nginx 的生产环境部署详解
Feb 02 Python
python导入坐标点的具体操作
May 10 Python
python celery分布式任务队列的使用详解
Jul 08 Python
Python Django的安装配置教程图文详解
Jul 17 Python
Django3.0 异步通信初体验(小结)
Dec 04 Python
区分python中的进程与线程
Aug 13 Python
Python装饰器用法实例总结
May 26 #Python
python 脚本生成随机 字母 + 数字密码功能
May 26 #Python
Python高级用法总结
May 26 #Python
关于Python的一些学习总结
May 25 #Python
windows下python和pip安装教程
May 25 #Python
python2.7实现爬虫网页数据
May 25 #Python
python sys.argv[]用法实例详解
May 25 #Python
You might like
福利彩票幸运号码自动生成器
2006/10/09 PHP
PHP执行速率优化技巧小结
2008/03/15 PHP
PHP Undefined index报错的修复方法
2011/07/17 PHP
php连接MSsql server的五种方法总结
2018/03/04 PHP
PHP使用curl_multi_select解决curl_multi网页假死问题的方法
2018/08/15 PHP
javascript 折半查找字符在数组中的位置(有序列表)
2010/12/09 Javascript
Jquery操作cookie记住用户名
2016/03/29 Javascript
常用Javascript函数与原型功能收藏(必看篇)
2016/10/09 Javascript
jQuery插件zTree实现清空选中第一个节点所有子节点的方法
2017/03/08 Javascript
ionic App问题总结系列之ionic点击系统返回键退出App
2017/08/19 Javascript
如何使用 vue + d3 画一棵树
2018/12/03 Javascript
关于node-bindings无法在Electron中使用的解决办法
2018/12/18 Javascript
[07:39]第一届亚洲邀请赛回顾视频
2017/02/14 DOTA
Python爬虫爬取美剧网站的实现代码
2016/09/03 Python
python之Character string(实例讲解)
2017/09/25 Python
深入浅析Python的类
2018/06/22 Python
pygame实现雷电游戏雏形开发
2018/11/20 Python
Django基础知识 web框架的本质详解
2019/07/18 Python
python asyncio 协程库的使用
2021/01/21 Python
利用Python实现最小二乘法与梯度下降算法
2021/02/21 Python
HTML5 CSS3新的WEB标准和浏览器支持
2009/07/16 HTML / CSS
Ellos丹麦:时尚和服装在线
2016/09/19 全球购物
美国首屈一指的高品质珠宝设计师和零售商:Allurez
2018/01/23 全球购物
萨克斯第五大道英国:Saks Fifth Avenue英国
2019/04/01 全球购物
Java中会存在内存泄漏吗,请简单描述
2016/12/22 面试题
药学专业大学生自荐信
2013/09/28 职场文书
单位介绍信范文
2014/01/18 职场文书
网上开商店的创业计划书
2014/01/19 职场文书
求职个人评价范文
2014/04/09 职场文书
企业承诺书怎么写
2014/05/24 职场文书
初三毕业评语
2014/12/26 职场文书
机器人总动员观后感
2015/06/09 职场文书
总经理致辞
2015/07/29 职场文书
教你快速开启Apache SkyWalking的自监控
2021/04/25 Servers
Golang 使用Map实现去重与set的功能操作
2021/04/29 Golang
python 实现图与图之间的间距调整subplots_adjust
2021/05/21 Python