About 321,000 results
Open links in new tab
  1. How do nested functions work in Python? - Stack Overflow

    Programmer’s note: Functions are first-class objects. A 'def' form executed inside a function definition defines a local function that can be returned or passed around. Free variables used in the nested …

  2. Nested Function in Python - Stack Overflow

    Oct 19, 2009 · I found this in an open-source project, doing something useful inside the nested function, but doing absolutely nothing outside it except calling it. (The actual code can be found here.) Why …

  3. python - Is nested function a good approach when required by only …

    Jan 29, 2011 · The nested functions are only declared but not called. So if you have defined 5 nested funtions in a function that you don't call then the execution time of the function is twice of the function …

  4. When is it good to use nested functions in Python?

    For mutable objects it's obviously ok to modify them. In the meantime, it's common to see the defaultarg hacks/idioms in Python2 One (maybe the only) disadvantage of the nested function is that it's difficult …

  5. python - When to create a nested function inside a function and when …

    Feb 16, 2021 · It is much easier to test and mock out _internal_func2 directly, without needing to call external_func2, which is great if external_func2 is especially complicated in itself to call. It would also …

  6. python - Real-world examples of nested functions - Stack Overflow

    May 23, 2017 · Your question made me curious, so I looked in some real-world code: the Python standard library. I found 67 examples of nested functions. Here are a few, with explanations. One …

  7. Call Nested Function in Python - Stack Overflow

    Jun 22, 2012 · Nested functions is not the way to structure code in Python (neither are classes). Take a look at modules.

  8. python - Local variables in nested functions - Stack Overflow

    The nested function looks up variables from the parent scope when executed, not when defined. The function body is compiled, and the 'free' variables (not defined in the function itself by assignment), …

  9. Python nested functions variable scoping - Stack Overflow

    Mar 7, 2011 · Python nested functions variable scoping [duplicate] Asked 14 years, 9 months ago Modified 3 years, 8 months ago Viewed 180k times

  10. python - What is the performance overhead of nested functions?

    Dec 29, 2012 · According to Raymond Hettinger's answer to "Is there an overhead when nesting functions in Python?", the code object is reused, so irrespective of the length of the inner function (for …