I'm studying Python through The Python Tutorial and I'm currently at Classes (chapter 9), but during the explanation of "scopes and namespaces" I got a question.
The author give this example:
def scope_test():
def do_local():
spam = "local spam"
def do_nonlocal():
nonlocal spam
spam = "nonlocal spam"
def do_global():
global spam
spam = "global spam"
spam = "test spam"
do_local()
print("After local assignment:", spam)
do_nonlocal()
print("After nonlocal assignment:", spam)
do_global()
print("After global assignment:", spam)
scope_test()
print("In global scope:", spam)
Source: http://docs.python.org/3.3/tutorial/classes.html#scopes-and-namespaces-example
From what I know until now, the keyword def
is used to define functions and functions are placed inside classes, but in this case he defined a function inside a function, so what is this function inside the another function called?
Is there a way I can access it from the outside the first function? For example from the namespace where scope_test is contained.
Would this functions inside functions work like "helper methods" called like that in other programming languages like Java and C# when they are private methods?