Question discussion

What is the output of the following Python code?def f(): try: return "a" finally: print("b", end="") print(f())

1152Medium DSSSB TGT Computer Science 0 replies

What is the output of the following Python code?

def f():
    try:
        return "a"
    finally:
        print("b", end="")
print(f())
  • Aa
  • Bab
  • Cb
  • Dba
Correct answer: D

Explanation

The finally block runs before the function returns, printing "b" first; then print displays the returned "a".

Discussion 0

Nobody has replied yet. Start the discussion!