Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Nested Functions | Variable Scope
Intermediate Python Techniques
course content

Course Content

Intermediate Python Techniques

Intermediate Python Techniques

1. Packing and Unpacking
2. Arguments in Function
3. Function as an Argument
4. Variable Scope
5. Decorators

bookNested Functions

This topic will not only help understand the nonlocal scope but also closures and decorators.

Functions are first-class citizens in Python. They can be:

  • Passed as arguments to functions;
  • Returned from functions;
  • Modified;
  • Assigned to variables.

Let's explore some examples:

In programming, a nested function is a function that is defined inside another function.

123456
def count_percent(num1, num2, num3): def inner(num): return num * 30 / 100 return (inner(num1), inner(num2), inner(num3)) print(count_percent(700, 300, 1000))
copy

Useful if you want to perform a complex task multiple times within another function without repeating code.

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 4. Chapter 4
We're sorry to hear that something went wrong. What happened?
some-alt