From the course: Functional Programming with Python
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Closure - Python Tutorial
From the course: Functional Programming with Python
Closure
- [Instructor] In a previous video, we talked about how in Python it's possible to return functions from other functions, and we saw some possible applications of doing this in our code base. Returning functions from other functions leads us to another very important concept in Python, and this is something called closure. So what is closure, exactly? Well basically, closure means that when we define a function that returns another function, the function we return still has access to the internal scope of the function that returned it. To see what I mean, let's code out an example that demonstrates closure. So first what we're going to do is create a function called create_printer, def create_printer. This is going to be very similar to the create printer function that we defined earlier. And then inside this create_printer function, we're going to define a variable called, my_favorite_number, and set it equal to…
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.