Exploring Scopes and Closures in Python
Martin Breuss
28:43
Description
Have you been wondering how scopes and closures work in Python? Maybe you’ve just heard about object.__closure__, and you’d like to figure out what exactly it does. In this Code Conversation video course, you’ll use the debugger Thonny to walk through some sample code and get a better understanding of scopes and closures in Python.
In this Code Conversation video course, you’ll:
You’ll also take a deep dive into the inner workings of Python by inspecting dunder objects to find out how Python handles and stores variables.
To get the most out of this Code Conversation, you should be familiar with scopes and variables in Python. You should also be comfortable defining your own functions and distinguishing between inner and outer functions.
What You'll Learn?
- Clarify code by refactoring it with descriptive names
- Learn how functions access variables in local and nonlocal scopes
- Understand how inner and outer function calls open and close their own scopes
More details
User Reviews
Rating
Martin Breuss
Instructor's CoursesAs someone who learned programming primarily through online resources, I feel that I have a good understanding of how important high quality learning material is.
With a background in education, I worked as a coding mentor, code reviewer, curriculum developer, and bootcamp instructor. Quality education and figuring out how to have fun while learning unfamiliar topics effectively has always been a big topic in my life. Real Python provides all that, and I’m happy that I can contribute.
In my day job I create online courses and teach on-site bootcamps around the world with CodingNomads. This position keeps me traveling, teaching, learning, discovering new places and new aspects of Python, as well as getting to know interesting and motivated students year-round.
When you learn to program, you’re learning to instruct a universal tool. People have described programming as the literacy of the 21st century, and I think that there’s something to that idea.
That doesn’t mean that you need to become a full-time software developer to apply your programming skills productively. Most likely there is way how your interests can benefit from being able to skillfully instruct your personal universal tool. And Python is a great language to get started with and also to keep going.
I’m happy to help out with thoughts and resources as well as encouragement.
If you’re stuck, remember that everyone gets stuck and if you feel you don’t know much, keep in mind that most of us feel that way quite often. Take a break, maybe go on a walk outside or do what it takes for you to keep yourself feeling good.
It’s easier to stick with something for the long term when you’re finding enjoyment in what you do. Remember that learning anything new is more of a marathon than a sprint. :)

Real Python
View courses Real Python- language english
- Training sessions 5
- duration 28:43
- Release Date 2023/01/05