5,321
edits
(→JSON) |
|||
Line 303: | Line 303: | ||
b = islice(a, 3) | b = islice(a, 3) | ||
list(b) # [0,1,2] | list(b) # [0,1,2] | ||
</syntaxhighlight> | |||
===Exceptions=== | |||
See [https://docs.python.org/3/library/exceptions.html https://docs.python.org/3/library/exceptions.html] | |||
;Try Catch | |||
<syntaxhighlight lang="python> | |||
try: | |||
something_which_may_raise() | |||
except AssertError as error: | |||
do_fallback() | |||
raise # Raise the previous error. | |||
else: | |||
do_something_if_no_exception() | |||
finally: | |||
finish_program_and_cleanup() | |||
</syntaxhighlight> | </syntaxhighlight> | ||