Skip to content

Instantly share code, notes, and snippets.

@lanfon72
Created December 14, 2015 11:51
Show Gist options
  • Select an option

  • Save lanfon72/d970c7416f315b9252e8 to your computer and use it in GitHub Desktop.

Select an option

Save lanfon72/d970c7416f315b9252e8 to your computer and use it in GitHub Desktop.
def try_else(x, y):
a = lambda x, y: x % y
b = lambda x, y: x / y
try:
result = a(x,y) + b(x,y)
f = open('Cookie', 'w+')
except ZeroDivisionError as z:
print(z)
# divide by zero.
except PermissionError as p:
print(p)
# can't open the file.
except Exception as e:
print(e)
# other exceptions.
else:
# all try condition no exception.
# means you have to close filestream.
f.close()
finally:
# clear all content or other things.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment