From the course: Python: Decorators
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Functions within functions - Python Tutorial
From the course: Python: Decorators
Functions within functions
- [Narrator] Now, one of the reasons why we're interested with working with functions within functions is because this is the basis for decorators. So let's kick things off with an example, let's say I have a function called fib_three. And within this function, I create a, another function called get_three, which returns the three Fibonacci numbers. So let's define fib_three. So fib_three accepts three arguments, a b and c, which are the three Fibonacci numbers. And then we have the function get_three within fib_three. So, and this one returns, the three Fibonacci numbers. So return a, b and c. Now functions are actually objects in Python. I can pass them around. I can store them in variables. I can also create the function, get_three and return the function back as a result. So let's do that. So return get_three. Now from Python's perspective, there's no difference between doing this and returning an integer or a…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.