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'我一定会执行!!!哈哈哈


原创粉丝点击