+ 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...?")

7th May 2022, 6:22 PM
Abdulwahab
Abdulwahab - avatar
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..
7th May 2022, 6:27 PM
Jayakrishna 🇮🇳
+ 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..
7th May 2022, 6:45 PM
Jayakrishna 🇮🇳
+ 1
Okay, so by calling parent, it automatically returns child. Thanks Jayakrishna🇮🇳
7th May 2022, 6:38 PM
Abdulwahab
Abdulwahab - avatar
+ 1
Magic methods like __init__() right, anyway thanks
7th May 2022, 6:57 PM
Abdulwahab
Abdulwahab - avatar
0
Yes. and that to also on when met some constraints.. You're welcome..
7th May 2022, 7:00 PM
Jayakrishna 🇮🇳
0
👍
7th May 2022, 7:37 PM
Abdulwahab
Abdulwahab - avatar