Skip to content

Instantly share code, notes, and snippets.

@SpikeXy
Last active October 2, 2017 01:44
Show Gist options
  • Save SpikeXy/913ebedb107bf9e9e1defdb6ef7e3e02 to your computer and use it in GitHub Desktop.
Save SpikeXy/913ebedb107bf9e9e1defdb6ef7e3e02 to your computer and use it in GitHub Desktop.
try_except_else_finally #python
# 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