I am learning enclosing functions, and have the following code:
def parent(x="Hello"):
text = x
def son():
print(text)
return son
print(parent())
Why does print(parent()) does not print "Hello", but rather prints <function parent.<locals>.son at 0x00000136A32E9EA0>?
I noticed that if I do the following, it will print "Hello":
def parent(x="Hello"):
text = x
def son():
print(text)
return son
akin = parent()
akin()
What would be the difference between one and another?
sonas a reference to the function instead ofson().sonby appending()toakin.son. In your 2nd sample you are assigningakinto the reference of the functionson. Both are references and needs to be executed if you want it toprint ("text")