Exploring Scopes and Closures in Python

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:

  • 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

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’s Included:

Downloadable Resources:

About Martin Breuss

Martin likes automation, goofy jokes, and snakes, all of which fit into the Python community. He enjoys learning and exploring and is up for talking about it, too. He writes and records content for Real Python and CodingNomads.

» More about Martin

Each tutorial at Real Python is created by a team of developers so that it meets our high quality standards. The team members who worked on this tutorial are:

← Browse All Courses