0

Why do functions not work?

When I use this type of code: def my_func(): def other_func(): #some stuff here def another_func(): #stuff my_func() The interpreter says that the nested functions aren’t defined, even when I’ve enclosed everything in brackets, corrected my typos, etc etc, the interpreter throws the same error, this is becoming frustrating, someone please help.

12th Aug 2021, 7:35 PM
Primal_Nexus
Primal_Nexus - avatar
6 Answers
+ 3
Primal_Nexus not the best idea to post a code you didn't. mean. Better paste in codeplayground and link it here. Ok... finally the answer was the scope problem😜😜
13th Aug 2021, 9:05 AM
Oma Falk
Oma Falk - avatar
+ 2
Primal_Nexus First error is that you cant have empty functions without a body, you would need to include the "pass" statement which does nothing, instead of those comments in the inner functions. Inner functions like this only exist in the scope of the outer function, meaning you can only call them inside the body of my_func(). Or you can return them from my_func() and use elsewhere.
13th Aug 2021, 4:27 AM
Giorgos
12th Aug 2021, 7:55 PM
Oma Falk
Oma Falk - avatar
0
Oma I’m confused as how this is supposed to help me
13th Aug 2021, 12:07 AM
Primal_Nexus
Primal_Nexus - avatar
0
Because the example code isn’t the code that wasn’t working
13th Aug 2021, 12:10 AM
Primal_Nexus
Primal_Nexus - avatar
0
Ok thanks a lot Giorgos D and Oma Falk
13th Aug 2021, 11:34 AM
Primal_Nexus
Primal_Nexus - avatar