Nested function | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Nested function

how can I call a nested function from function that are out side of the main function def main() def a() def fun() def b() # do something # call function a

4th Jan 2017, 7:43 AM
yonipick
yonipick - avatar
2 Answers
+ 1
since a() is a local function inside the main function, without using global functions i dont see any elegant way how you could run it from another function outside of the main function. But my solution would be: def main(call_a = False): def a(): print("hi") if call_a is True: a() def func(): def b(): call_nested_func_inside_main = True main(call_nested_func_inside_main) b() func() So you call a nested function by using some arguments from the functions outside of the parent function.
4th Jan 2017, 7:56 AM
Alireza Bahram
Alireza Bahram - avatar
0
I have follow up question what if both function are in class the class as two nested function
4th Jan 2017, 3:19 PM
yonipick
yonipick - avatar