Accessing nested functions | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 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 Respostas
+ 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