except names the family LookupError, and its second names Exception.
def fetch(box, k):
try:
return box[k]
except LookupError:
return "missing"
except Exception:
return "bad"
print(fetch({"x": 1}, "y"), fetch([1, 2], -3), fetch((5, 6), "0"))
What does the program print?Log in to join the discussion.
Loading…