try:
#Try something that might raise an exception
except <exception specifier>:
#Code here will only run if the exception that came up was the one specified
except:
#Except clause without specifier will catch all exceptions
else:
#Executed if try clause doesn't raise exception
#You can only have this else here if you also have except blocks
finally:
#Runs no matter what
你对
try
、except
、else
和finally
的理解似乎是错的。你知道吗下面是从https://docs.python.org/2/tutorial/errors.html来看它们是如何协同工作的:
相关问题 更多 >
编程相关推荐