python学习十(多继承,多态,异常)
来源:互联网 发布:王陆807和语料库 知乎 编辑:程序博客网 时间:2024/06/05 07:46
1、多继承--继承有先后顺序,如果父类中没有,就从上一级父类找
多态
#encoding=utf-8class Test: def test(self): print('test……………………')class TestA(Test): def test(self): print('testA…………………………') def app(self): print('A…………………………app') def A(self): print('A…………………………')class TestB(Test): def test(self): print('testB…………………………') def app(self): print('B…………………………app') def B(self): print('B…………………………')class MyTest(TestA, TestB): passmyTest = MyTest()myTest.test()myTest.app()myTest.B()2、异常
#encoding=utf-8try: num = 100 print num open('my.txt')except NameError,errorMsg: print ("产生错误1%s"%errorMsg)except IOError,errorMsg: print ("产生错误2%s"%errorMsg)else: print ('没有异常')finally: print ("我一定会执行!!!哈哈哈")执行结果如下:
100产生错误2[Errno 2] No such file or directory: 'my.txt'我一定会执行!!!哈哈哈
阅读全文
0 0
- python学习十(多继承,多态,异常)
- python的学习(十)----异常处理(1)
- Python学习系列十:异常处理
- python特性(十):GeneratorExit异常
- (十)继承四(多继承)
- Python 异常继承体系
- VB.net学习笔记(十)继承
- JAVA学习十:继承
- 学习python的第四十七天-第九章 异常处理
- Python学习(十)------- 模块
- python 学习笔记(十)
- Python学习笔记(十)
- Python学习笔记(十)
- python学习(二十)
- java学习之十(异常篇)
- 异常处理---SpringMVC学习笔记(十)
- java学习日志(十)-- 异常
- 异常处理---SpringMVC学习笔记(十)
- [NOIP模拟赛]单向道路
- 褚时健84岁再成亿万富翁
- JavaScript基础
- MySQL的InnoDB索引原理详解
- 界面编码报错:Page-encoding specified in XML prolog (UTF-8) is different from that specified in
- python学习十(多继承,多态,异常)
- Mybatis--更新
- Balanced Numbers 数位DP+3进制压缩
- 调用百度翻译接口demo(完整ajax请求)
- windows下使用pthread
- 手把手教你Android手机与BLE终端通信--搜索
- 用quartz进行定时任务的开发
- 系统监控工具
- 在进行C#编程时候,有的时候我们需要判断一个字符串是否是数字字符串,我们可以通过以下两种方法来实现。 【方法一】:使用 try{} catch{} 语句。 我们可以在try语句块中试图