An unofficial version of the Python glossary (official glossary) that's meant for average Python users.
The definitions in the below glossary are colloquial and some of these terms never appear in the official Python documentation.
These terms are all about looping and objects you can loop over.
Looping over an iterable object.
for loop is the epitome of iteration, but there are many other ways to iterate over an iterable in Python.
List comprehensions iterate.
Tuple unpacking iterates.
* operator in a function call iterates (see Unpacking iterables into function arguments).
* operator in a list literal iterates (see Unpacking iterables into iterables).
(Our perspective as Python users)
Anything you can loop over with using a
for loop or by various other forms of iteration.
More on iterables in What is an iterable.
Anything that can be passed to the built-in
iter function to get an iterator from it.
If you're inventing your own iterable class, also see How to make an iterable.
These terms are all about objects that "contain" other objects (sometimes called collections or data structures). While we use the word "contain" to talk about this relationship, it's not quite the kind of objects nested in objects you might imagine: data structures contain pointers rather than objects in Python.
An ordered collection of objects.
Sequences have a length (via the built-in
len function), can be indexed (starting at
0), and are iterable.
Sequences can also be thought of as a tuple-like object or a list-like object. Tuples, strings, and lists are all sequences.
See What is a sequence for more on sequences.
A dictionary-like object.
An object which stores key-value pairs and supports key lookups using square brackets (
]), among other features we expect dictionary-like objects to support (such as being an iterable).
Like sequences, mappings are iterable.
See What is a mapping? and Creating a mapping for more on how to create your own mappings.
An immutable sequence. Tuples act like a list, but they can't be mutated. While tuples could just be thought of as immutable lists, we usually use the two quite differently: tuples are for storing a fixed number of values, often of different types.
For more on the nature of tuples see How to make a tuple and Mutable tuples.
A special syntax for building a new list/set/dictionary out of an old iterable. Comprehensions build a new iterable out of an old one while either filtering items down based on a condition or modifying each item based on a mapping expression.
See What are list comprehensions for more on list comprehensions. See Set and dictionary comprehensions for more on set and dictionary comprehensions.
These terms are all about how variables work in Python. There's a level of indirection in Python's variables (through pointers) that makes this concept a bit more complex than it might seem at first glance.
A name used to refer to an object. Variables point to objects in Python (see pointers).
For much more on the nature of variables in Python, see Overlooked facts about variables and objects in Python.
Different variables exist is different scopes.
A sort of "link" to an object, usually a link from a variable to an object or from a data structure to an object.
In Python, variables are pointers (they don't contain objects but point to them). Also, data structures contain pointers in Python.
For much more on the nature of pointers in Python, see Overlooked facts about variables and objects in Python.
Assignment points a variable to a value. It's important to note that assignment doesn't copy anything and multiple variables can point to the same value.
Assignments change a variable while mutations change a value (see The 2 types of "change" in Python). Assignments don't usually cause mutations (see Mutating with an assignment statement and Augmented assignments mutate).
We usually think of the
= sign when we think of assignment.
for loops, function definitions, and module imports are also assignments (see Assignment isn't just about the equals sign).
For much more on the nature of variables in Python, see Overlooked facts about variables and objects in Python.
A special syntax for assigning a name to each item in an iterable. This syntax is usually used with iterables with short iterables that have a known length (most often tuples). See the tuple unpacking article for more.
A name that lives on an object.
If you see
x.y in Python code,
y is an attribute of
Sometimes the term qualified name is used to describe the full "path" to a name using dotted attribute notation.
For more on attributes, see Where are attributes stored and How attribute lookups and assignments work.
A "space" where names live.
This term comes up when discussing:
a.baccesses the name
aaccesses the name
afrom a namespaces that's currently "in-scope" (see scope)
When discussing variable access, we usually use the word scope instead of the word namespace. The word namespace comes up most often when discussing objects that store attributes (such as modules and classes).
We take namespaces seriously in Python. Somewhat uniquely (not all programming languages have this), each module in Python has a separate namespace (more in Each module has its own global scope). The Zen of Python says "namespaces are one honking great idea -- let's do more of those!"
For a very deep look at namespaces and scope see Python Scopes and Namespaces from the very technical Python Classes Tutorial (I don't this unless you're very interested).
A place that variables live. When you lookup a variable name, Python first checks the local scope, then the enclosing scopes, then the global scope, and finally the built-ins scope (this name search is sometimes called LEGB). The terms namespace and scope are closely related (scopes rely on namespaces to work) that the term "namespace" is sometimes used when "scope" would work as well.
Unlike many other programming languages, in Python, there's no such thing as "block-level scope".
Dunder stands for "double underscore".
Dunder variables have two underscores on either side:
Dunder variables and dunder methods act define a contract between Python programmers and the Python interpreter. The official Python documentation never uses this phrase: "special attribute" is used instead of "dunder attributes" and "special method" is used instead of "dunder method". You'll sometimes hear Python programmers refer to these as magic methods, though that term seems to have fallen out of fashion.
Example dunder variables include
For more, see Dunder variables.
These terms are all about how objects work in Python (note that "object" is a very big term in Python).
Any "thing" in Python. An object represents data has attributes and methods. The term "object" is tricky to define simply because everything is an object (functions, modules, classes, and class instances are all objects).
Some objects are mutable and some are immutable. Objects cannot contain other objects (see data structures contain pointers).
Changing an object. Mutating an object means to change the state of that object (in any way).
Mutating changes an object, while assignment changes a variable (see The 2 types of "change" in Python).
An object that can be changed (i.e. mutated). The "value" of a mutable object can change (meaning the data it contains). An immutable object is one that cannot change.
An object that cannot be changed (i.e. mutated). The value of an immutable object cannot change. Tuples are examples of immutable objects.
This is a slightly fuzzy term because sometimes the data an object contains can remain constant while its sense of equality changes (see Mutable tuples).
See mutable for mutable objects.
An object that can be passed to the built-in
hash function to get its hash value.
The hash value of an object is meant to semi-uniquely represent that object.
All objects in a set must be hashable and keys in a dictionary must be bashable.
See what are hashable objects for more.
Whether two objects represent the same data.
Equality can be tested with the
You can control equality on your own objects by defining the
Also see identity.
Whether two references/pointers refer to the same object.
Identity can be tested with the
For more on equality versus identity, see Equality vs identity and When is equality the same as identity.
These terms are about importing code from other files and creating Python files that are meant to be imported.
A Python file (
.py) that's meant to be imported by other
Importing a module runs the code within that module and provides access to a module object which stores that module's functions, classes, and other data.
Variables defined within a module which are not inside a function or class are called global variables (see Local and global variables). Each module's global variables are accessible as attributes on the module object (see Each module has its own global scope).
Python caches modules after they're imported, so importing the same module twice will return the same module object.
A Python module created out of a directory (instead of a single
Python packages are created by making a directory containing a
__init__.py file (see What's
Python packages can contain submodules (via other
.py files within the package directory) and subpackages (via other package directories within the package directory).
It is possible to create a Python package without a
__init__.py file, but that creates an implicit namespace package.
You shouldn't create namespace packages unless you shouldn't make unless you specifically need a namespace package (they're very rare and you very likely do not need a namespace package).
Not to be confused with an installable Python package, which is a bundle of one or more packages (usually just one) which is usually installed from the Python package index (PyPI). See installing Python packages for more on installable packages.
The modules and packages that are distributed with Python (and to be part of considered) are collectively called "the Python standard library".
The Python standard library includes
statistics, and dozens of other libraries.
The documentation contains a full list of Python's standard library modules. Doug Hellman's Python Module of the Week includes additional explanations of many popular standard library modules.
Python packages which are not included with Python (and which you didn't write yourself) are often called third party modules or third-party libraries.
These terms are about making Python programs and running Python interactively.
A Python file (
.py) that is meant to be run directly.
Python scripts are usually run from as a command-line program, from the system command prompt (a.k.a. terminal).
Python scripts are created by making a Python modules which is meant to be imported (see making a main function and module vs script).
A script or program that is meant to be run from your computer's command prompt (a.k.a. terminal). The command prompt is a program which accepts commands and programs to run.
You can usually start a Python REPL from your command prompt by typing
Or you can run a Python script by passing a Python filename to the Python command.
An input to a program. Not to be confused with a function argument, which acts as an input to a function.
Command-line arguments passed to Python can be read from
sys.argv (see Accessing command-line arguments).
An environment for repeatedly entering Python statements and seeing the results of those statements.
When you launch Python without giving it any command-line arguments (by typing just
python3 from your system command-prompt) you'll enter the Pythen REPL.
REPL stands for Read Evaluate Print Loop; this describes what Python does as you use the REPL: it reads the statement you've typed, evaluates it when you hit the Enter key, prints out the result of that statement, and then waits you to type another statement again.
The interactive Python interpreter is the official name for the Python REPL, but it goes by many names: Python shell, Python prompt, and Python console are all popular alternate names (in addition to REPL).
These terms are all about functions and callables.
A way to make reusable code: functions store code to be called later. Functions can have inputs, in the form of arguments, and an output, in the form of a return value. Functions are used by calling them.
Functions in Python are also objects (see Everything is an object).
See Calling a function and How to make a function.
An object which can be "called".
If you have a variable that represents a callable object, you can "call" that object by putting by putting parentheses after it (e.g.
Any arguments passed to that callable, should be put inside the parentheses.
Functions are callable (calling them runs the code in the function). Classes are also callable (calling them returns a new instance of a class). You can even invent your own callable objects (see What is a callable). For more on this topic, read Callables: Python's "functions" are sometimes classes.
An input to a function, a class, or another callable. Arguments can be specified positionally or by their name (see positional vs keyword arguments). An argument can be made "optional" by defining a default value for that argument).
Note that the Python documentation draws a distinction between parameter (the variable name used) and argument (the actual object which will be passed-in to the function), but this distinction is often ignored by Python users (we often to say "argument" when "parameter" might be more correct).
Decorators augment the behavior of functions and classes.
Decorators can be applied to a function or class by using an
@ symbol to "decorate" that function or class.
Decorators meant for decorating functions are called "function decorators". To make a function decorator, you'll make a function that accepts a function and returns a new function (technically this could be implemented as any callable that accepts a function).
Decorators meant for decorating classes are called "class decorators". To make a class decorator, you'll make a function that accepts a class, modifies that class, and returns the same class (typically).
For more see what is a decorator, how to make a decorator, and making a class decorator.
These terms are all about classes and class instances.
A way to couple data and functionality. Classes store data within each instance of that class (within the attributes) or each instance. You can make a new class instance by calling it a class. The functionality of a class comes from its methods.
The word "type" is a synonym for class.
Popular built-in classes in Python include
Every object in Python has a type/class (see Classes are everywhere).
Also see What is a class.
An object with a specific type.
A list object is an "instance" of the
You can make a new instance of a class by calling that class.
Class instances store attributes that represent the data for that class instance. Updating an attribute on a class instance changes the data stored with that instance. Actions can be performed on class instances by calling methods on them.
Within methods, the variable
self is usually used to represent the instance that method will operate on (see What is self).
When discussing class instance creation, Python programmers sometimes use slightly jargony Computer Science phrases such as "construct a new instance" or "instantiate the class". Those phrases are more often heard in other programming languages (like Java) but do come up in Python.
A function which is defined on a class and meant to operate on instances of that class. Methods define actions that can be performanced on class instances.
The first argument in every method is usually called
self (see What is self).
When a method is called on a class instance, the instance will automatically be passed-in as the first positional argument.
A method that's called automatically when a new class instance is made.
After calling a class, Python makes a new class instance and calls the
__init__ (a dunder method) on that new instance.
This method should accept the same arguments that the class accepts.
You'll occasionally hear programmers who moved from other programming languages refer to
__init__ as the "construct method".
In Python, our constructor method is
__new__ and it constructs a new class instance.
By the time
__init__ is called, the instance already exists (it's passed in as the first argument,
__new__ method is rarely defined, so while saying "constructor" might be a bit confusing, most Python programmers will assume you mean the
See What is
Dunder stands for "double underscore".
The most common dunder methods are
See What are dunder methods.
The official Python documentation uses the phrase "special methods" ("dunder" isn't present in the documentation). You'll also sometimes hear Python programmers refer to these as magic methods, though that term seems to have fallen out of fashion.
Also see see dunder variables.
These terms are all about objects that generate values as you loop over them. I usually use the term "lazy looping" as an umbrella term for this concept.
(Our perspective as a Python user)
A lazy iterable that gets consumed as you loop over it.
Once all items have been consumed from an iterator, it is exhausted and will appear empty when looped-over again.
Iterators can be looped-over (see iteration) or they can be passed to the built-in
next function to get just their next item.
Generators are iterators and so are many other iterables in Python (see Generators are iterators).
You can also make an iterator class (see How to make an iterator) but it's unusual to do so.
(Python's perspective) Iterators power all forms of iteration in Python (iterables are iterator-powered). See The Iterator Protocol.
Also see What is an iterator.
A comprehension-like syntax for creating a generator object. You can think of generator expressions as a "generator comprehension"; that term isn't currently used officially or collquially but it probably should be. See How to write a generator expression for more.
A function that has one or more
yield statements within it.
Generator functions do not run when called; instead they return a generator object which will start running the function as it's being looped over.
The Python documentation (confusingly in my opinion) sometimes refer to generator functions as simply generators.
See What is a generator function for more.
The return value of a generator function or the result of running a generator expression.
Generator objects (a.k.a. generators) are iterator.
Generators are often considered the easiest way to make an iterator.
They can also be used for implementing coroutines, though that's usually done using Python's
Note that I've purposely defined the term "generator" differently than the Python documentation. The Python documentation uses the term generator iterator to refer to a generator object, but the generator to refer to a generator function. From my experience, Python programmers tend to use the term "generator" to refer to generator objects rather than generator functions.
These terms are frequently used throughout Python Morsels exercises, screencasts, and articles. If you're an intermediate-level Python programmer and you'd like an excuse to level-up your skills even more, give Python Morsels a try.
Need to fill-in gaps in your Python skills?
Sign up for my Python newsletter where I share one of my favorite Python tips every week.
Need to fill-in gaps in your Python skills? I send weekly emails designed to do just that.