How to get local variables updated, when using the `exec` call?

Viewed 19613

I thought this would print 3, but it prints 1:

# Python3

def f():
    a = 1
    exec("a = 3")
    print(a)

f()
# 1 Expected 3
3 Answers
Related