ProgrammingHardIBM · Deloitte pattern
What is printed?
What is printed?
try:
print("a")
except Exception:
print("b")
else:
print("c")
finally:
print("d")- A. a d
- B. a c d
- C. a b d
- D. a b c d
Correct answer: B. a c d
No exception is raised, so the try block prints 'a', the else block (which runs exactly when no exception occurred) prints 'c', and finally always runs, printing 'd'. The except block is skipped entirely.
More Python Programming questions
- What is printed? python def h(): try: x = 1 / 0 except ZeroDivisionError: return "caught" else: return "no error" finally: print("always")…
- What is printed? python def k(): try: return "try" except Exception: return "except" else: return "else" print(k())
- What is printed? python s = "placement" print(s[-100:5])
- What is printed? python s = "abcdef" print(s[10:20])
- What is printed? python s = "abcdef" s2 = list(s) s2[1:3] = ["X", "Y", "Z"] print("".join(s2))
- What is printed? python s = "abc" print(s 0, type(s 0))