Python中函数嵌套以及函数嵌套的继承

# a = 10
# b = 0
# c = 5
# try:
#     print("a的值是:%d,b的值是:%d"%(a,b))
#
#     f = c.open("a.txt")
#     print(f)
#     d = a / b
#     print("%d除以%d的值为:%d"%(a,b,d))
# except (ZeroDivisionError,AttributeError) as msg:
#     print("程序出错了")
#     print(msg)
# finally:
#     print("程序运行结束了~")




# 函数的嵌套
# import time
# try:
#     f = open("test.txt")
#     try:
#         while true:
#             content = f.readline()
#             if len(content) == 0:
#                 break
#             time.sleep(2)
#             print(content)
#     finally:
#         print("程序运行结束~")
#     f.close()
#     print("关闭文件")
# except:
#     print("没有这个文件")

def test1():
    print("--test1-1--")
    print(num)
    print("--test1-2--")

def test2():
    print("--test2-1--")
    test1()
    print("--test2-2--")

def test3():
    try:
        print("--test3-1--")
        test2()
        print("--test3-2--")
    except Exception as result:
        print("捕获到了异常~")
        print(result)
print("--test4-1--")
test3()
print("--华丽的分割线--")
test2()

 

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值