Last active
October 2, 2017 01:44
-
-
Save SpikeXy/913ebedb107bf9e9e1defdb6ef7e3e02 to your computer and use it in GitHub Desktop.
try_except_else_finally #python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# try_except_else_finally 例子,如果没有错误发生,可以在except语句块后面加一个else,当没有错误发生时,会自动执行else语句: | |
try: | |
print('try...') | |
r = 10 / int('2') | |
print('result:', r) | |
except ValueError as e: | |
print('ValueError:', e) | |
except ZeroDivisionError as e: | |
print('ZeroDivisionError:', e) | |
else: | |
print('no error!') | |
finally: | |
print('finally...') | |
print('END') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment