Search notes:

Python: nested functions

In Python, it's possible to nest functions. Apparently, these are also(?) called inner functions.
#!/usr/bin/python3

def func():

    print("func was called")

    def nested_func():
        print("nested_func was called")

        def doubly_nested_func():
            print("doubly_nested_func was called")

        doubly_nested_func()

    nested_func()

func()
#
# func was called
# nested_func was called
# doubly_nested_func was called
Github repository about-python, path: /statements/def/nested.py

See also

The def statement.

Index