Skip to content
CodeKruPro

finally changes the variable after return

Predict the outputMedium-HardPython only
main.py
def number():
    x = 1
    try:
        return x
    finally:
        x = 5

def items():
    data = ["a"]
    try:
        return data
    finally:
        data.append("b")

print(number())
print(items())

This question is part of Pro+

Pro+ opens every question in Interview Prep and the mock interview. Every article and the first 2 questions of each topic stay free. Hands-on Selenium and API tasks follow their course lesson's own lock.

See Pro+

Already have Pro+? Sign in