Why "exec" method is not working inside the function?

Execution methods works outside the function

exec('a=10\nb=11\nd=a+b')
print(d)

exec methods not working inside the function

def addition(string):
     exec(string)
     return d
addition("a=10\nb=11\nd=a+b")

Here’s a nice answer about this sort of thing on StackOverflow: python - How does exec work with locals? - Stack Overflow