Back to questions
JuniorTheoryCommon
What does the program print?
def check(x):
try:
y = 10 / x
except ZeroDivisionError:
return "zero"
else:
return "ok"
finally:
print("done", end=" ")
print(check(0))done zero
- Expecting
zero, as ifreturnleft the function at once:finallyruns on the way out oftry, even past areturn, sodoneis printed first. - Expecting
zero done:finallyruns insidecheck, before the function hands back"zero", so the outerprintgets the value only afterdoneis out.
- What does
print(check(5))print? - Why does
print("done", end=" ")keep both words on one line?