loop
← All sections

Module 4 · Functions, tuples, dictionaries, exceptions, and data processing

Scopes in Python

Where does a variable live, and who can see it? Meet local and global scope, the global keyword that crosses between them, and exactly what happens to the values you hand a function.

Begin lesson 1 →
  1. 1Functions and scopesWhere a variable lives: local names exist only inside their function; globals are visible to read.
  2. 2The global keywordWhen a function really must change a global variable — and why it's rarely the right call.
  3. 3How a function interacts with its argumentsNumbers arrive as copies; lists are shared — the same value, two very different behaviours.