Python namespace
A mapping from names to objects; each module, function call and class has its own, which is why the same name can mean different things in different places.
In more detail
Python keeps a function's local variables in a namespace that behaves like a dictionary, and locals() returns it. That is why format(**locals()) can fill a template from your variable names. Modules give their contents a namespace too, reached with a dot, as in math.pi.
Related terms
- scope — The region of a program where a name can be seen and used.
- locals() — A built-in function that returns a dictionary of the current local variable names and their values.
- module — A file of code whose functions, classes and variables other files can use by importing it.
Taught in
- Dictionaries And String Formatting — Hands-on Python: Complete Video Course & Book