What will be the output of the following Python code? def foo(): try: return 1 finally: return 2 k = foo() print(k)

Questions & AnswersCategory: PythonWhat will be the output of the following Python code? def foo(): try: return 1 finally: return 2 k = foo() print(k)
Lokesh Kumar Staff asked 2 years ago

What will be the output of the following Python code?

def foo():
    try:
        return 1
    finally:
        return 2
k = foo()
print(k)

a. error, there is more than one return statement in a single try-finally block
b. 3
c. 2
d. 1