Exercise: Python Closure
The function
secret_keeper
holds a secret that is only revealed by its inner function reveal
. In other words, we are creating a closure. However, there's a small error. Fix the mistake to turn the code into a fully working closure.def secret_keeper():
secret = '🤫🎁'
def reveal():
return secret
### adjust here ###
return reveal()
###################
get_secret = secret_keeper()
print(get_secret()) # expected: 🤫🎁
Python
Setting up Python environment...
Output