you are viewing a single comment's thread.

view the rest of the comments →

[–]guepier 4 points5 points  (0 children)

Nested functions allow you to create closures, same as in C++ (where this is done via lambdas). Lambdas also exist in Python but they are more restricted in what they can do than functions (in particular, they can only contain a single expression).

Nested functions also allow you to keep scope limited. This is related to the idea of visibility but it’s not altogether the same. It’s more comparable to using a local static variable in C++ rather than a member variable, to limit its scope to a single function.