+ 1
Accessing nested functions
So I tried accessing both print statements in one go but it didn't work, is there a way to do this?. Here's the code: def parent(): def child(): print("Yay, you got me!") print("And...?")
6 Respuestas
+ 1
def parent():
def child():
print("Yay, you got me!")
print("And...?")
return child() # just call
parent()
#you need to call the function, to use it anywhere..
+ 2
Not automatically. Am returning calling child() it returns nothing..
It will be like also
def parent():
def child():
print("Yay, you got me!")
print("And...?")
child() # just call
parent()
#or can be also:
def parent():
def child():
print("Yay, you got me!")
print("And...?")
return child # return function
parent()() #call returned value
#normal function not called automatically, only magic methods will be.
# you're welcome..
+ 1
Okay, so by calling parent, it automatically returns child. Thanks Jayakrishna🇮🇳
+ 1
Magic methods like __init__() right, anyway thanks
0
Yes. and that to also on when met some constraints..
You're welcome..
0
👍