1、多继承--继承有先后顺序,如果父类中没有,就从上一级父类找
多态
#encoding=utf-8 class 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): pass myTest = MyTest() myTest.test() myTest.app() myTest.B()2、异常
#encoding=utf-8 try: 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' 我一定会执行!!!哈哈哈