Live Engine
Select Topic
easyClosures And Decorators
A developer returns an inner function from an outer function. What does this print, and what keeps the captured variable alive after outer() returns?
Code
def outer(msg):
def inner():
return f"Message: {msg}"
return inner
greet = outer("hello")
farewell = outer("goodbye")
print(greet())
print(farewell())
print(greet is farewell)
print(greet.__closure__[0].cell_contents)