java 的 try catch finally 对应 python3 的 try except finally
python3 写成这样:
try: #
1 / 0
except Exception as e:
print( "Exception: ", e ) # 打印 Exception: division by zero
finally:
print( "finally" ) # 打印 finally
#
python2 写成这样:
try: #
1 / 0
except Exception, e:
print "Exception: ", e
finally:
print "finally"
#
本文对比了Java的try-catch-finally与Python 3的try-except-finally语法,并通过示例展示了如何在Python中处理除零错误,强调了finally块在两种语言中的作用。
1114

被折叠的 条评论
为什么被折叠?



