python学习十(多继承,多态,异常)

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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值