标签:答案 一个 open pen state ide ISE tput 分享图片
try:
f = open("/tmp/output", "w")
f.write("hello")
#raise Exception("something wrong")
finally:
print("closing file")
f.close()
def func1():
try:
return 1
finally:
return 2
def func2():
try:
raise ValueError()
except:
return 1
finally:
return 3
print(func1())
print(func2())
def func1():
try:
print ‘in func1 try: try statement, will return 1‘
return 1
finally:
print ‘in func1 finally: try statement, will return 2‘
return 2
def func2():
try:
print ‘in func2 try: raise error‘
raise ValueError()
except:
print ‘in func2 except: caught error, will return 1!‘
return 1
finally:
print ‘in func2 finally: will return 3‘
return 3
print func1()
print func2()
in func1 try: try statement, will return 1
in func1 finally: try statement, will return 2
2
in func2 try: raise error
in func2 except: caught error, will return 1!
in func2 finally: will return 3
3
def func2():
try:
print ‘in func2 try: raise error‘
raise ValueError()
except IndexError:
print ‘in func2 except: caught error, will return 1!‘
return 1
finally:
print ‘in func2 finally: will return 3‘
return 3
print func2()
in func2 try: raise error
in func2 finally: will return 3
3
标签:答案 一个 open pen state ide ISE tput 分享图片
原文地址:https://www.cnblogs.com/songxuexiang/p/9102362.html