ProgrammingHardGATE CS · Product-company placement
What is printed?
What is printed?
def f():
for i in range(3):
try:
return i
finally:
if i == 0:
continue
print(f())- A. 0
- B. 2
- C. None
- D. 1
Correct answer: D. 1
Since Python 3.8, continue is allowed in finally; it discards the pending return 0 and the loop goes on. On i = 1 the finally does nothing, so return 1 completes.
More Python Programming questions
- What is printed? python def f(): try: raise KeyError("k") finally: return "swallowed" try: print(f(), end=" ") except KeyError…
- What is printed? python try: try: 1 / 0 except ZeroDivisionError: raise ValueError("v") except ValueError as e…
- What is printed? python try: try: {}["x"] except KeyError as k: raise RuntimeError("r") from None except RuntimeError as e…
- What is printed? python out = [] for x in [1, 0, "a"]: try: r = 10 / x except (ZeroDivisionError, TypeError) as e…
- What is printed? python class AppError(Exception): pass class DBError(AppError): pass try: raise DBError("db") except Exception…
- What is printed? python def f(): try: raise ValueError("a") except ValueError as e: err = e return err x = f() print(type(x).name, x.args…