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 a
for loop or by various other forms of iteration.
More on iterables in What is 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.
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.
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.
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.
Truthiness asks the question "if we convert this object to a Boolean, will we get
All objects in Python have a "truth value": they're either truthy or falsey.
All objects are truthy by default unless they define a
__len__ method to customize their sense of truthiness.
In general, truthiness checks for non-zeroness and non-emptiness.
Empty collections (such as
()) are falsey, but non-empty collections are truthy.
Numbers that represent zero (
decimal.Decimal("0")) are falsey, but all other numbers are truthy.
None is also falsey.
See truthiness in Python for more on truthiness.
Strings, tuples, and lists in Python are ordered "lexicographically".
Lexicographical ordering essentially means "similar to alphabetical ordering".
"animal" < "apple" is
True because since the first letters are equivalent, the second letters are compared and
"n" < "p" (in both Unicode and the alphabet).
(1969, 5, 18) < (1969, 7, 16) is
True because since the first indexes are equivalent, the second indexes are compared and
5 < 7.
See more in the article tuple ordering in Python.
A file-like object is an object that behaves like a file.
Files are file-like objects, but so are the standard input (
sys.stdin), standard output (
sys.stdout), and standard error (
sys.stderr) file streams.
It's also possible to create your own file-like objects.
See File-like objects in Python for more.
An object that acts like the built-in
set class is a set-like object.
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.
For much more on the nature of variables in Python, see Overlooked facts about variables and objects in Python.
Different variables exist in 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.
For much more on the nature of pointers in Python, see Overlooked facts about variables and objects in Python.
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).
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.
Sometimes the term qualified name is used to describe the full "path" to a name using dotted attribute notation.
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!"
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 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).
Changing an object. Mutating an object means to change the state of that object (in any way).
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
An object's string representation determines what happens when Python converts that object to a string.
All Python objects have two possible string representations: the user-readable representation (
str) and the human-readable representation (
The representation for
str defaults to the same representation as
repr, so in general most objects only define one of these two string representations:
See customizing the string representation of your Python objects for more on controlling the string representation of your class instances.
Also see the article string representations for classes.
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.
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 as a command-line program, from the system command prompt (a.k.a. terminal).
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.
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 Python 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 for 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.
An object which can be "called".
If you have a variable that represents a callable object, you can "call" that object 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 either 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 say "argument" when "parameter" might be more correct).
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).
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). You can make a new class instance by calling the 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.
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.
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 creates a new class instance and calls the
__init__ method (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 "constructor method".
In Python, the 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 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 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.
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 colloquially 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.
Generator objects (a.k.a. generators) are iterators.
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.
The terms are all about Python's "syntax", meaning the symbols, words, and rules that make up valid Python code.
"Syntactic sugar" refers to a programming language syntax that's simply a shortened or improved version of an existing syntax. This phrase usually refers to Python syntax features that are not essential, but are nonetheless helpful.
Python's decorator syntax and list comprehensions are examples syntactic sugar. They make the lives of Python users "sweeter", but we could accomplish the identical tasks even if those special syntaxes didn't exist.
** operators in Python are sometimes referred to as "splat" and "double-splat", especially by Ruby programmers.
These operators are also sometimes referred to as "star" and "double-star".
Note that this refers to the "unary" or "prefix"
** operators, meaning they go before a name (
**b) but not in-between two names (
Unfortunately, these operators do not have a well-defined name in Python. They also have a wide variety of uses, including accepting any number of positional arguments and accepting arbitrary named arguments.
For more on the unary
** operators see the various screencasts and articles on asterisks in Python.
:= operator, which is used within an assignment expression.
:= operator is often called the "walrus operator" because it looks like a walrus on its side (note the tusks).
This operator was added in Python 3.8.
For more, see Python's walrus operator.
These terms are all about Python code style.
A programming style characterized by focusing on the behavior of an object instead of the class (a.k.a. type) of that object.
For example, a function that accepts a writable file-like object might accept any object that has a
Duck typing often works well with an EAFP programming style. For example, if a function accepts a readable file-like object, it may assume the given argument is an iterable of lines and loop over it. If a non-iterable was given, the program would raise an exception, either explicitly or implicitly.
For more, see Duck Typing in Python.
EAFP refers to a programming style where an operation is assumed to work, attempted, and then exceptions are handled as needed.
EAFP often involves the use of more
except blocks and fewer
EAFP examples include:
KeyErrorexception if it doesn't
EAFP (Easier to Ask For Forgiveness Than Permission) contrasts LBYL (Look Before You Leap).
LBYL refers to a programming style where assumptions are explicitly checked before moving forward.
LBYL often involves more
else blocks and fewer
LBYL (Look Before You Leap) contrasts EAFP (Easier to Ask For Forgiveness Than Permission). LBYL is slightly less common in Python than EAFP because race conditions are less of a concern with EAFP-style programming and asking questions of objects is tricky due to our use of duck typing in Python.
Note that we can often avoid the issue of LBYL vs EAFP entirely by delegating to functions, like the dictionary
get method, which hide implementation details from us.
Any technique that extends or modifies the behavior of objects, typically objects you wouldn't normally alter, while a Python program is running.
Monkey patching is often used to temporarily replace an object or function, sometimes for the purpose of automated tests.
redirect_stdout will temporarily replace the usual standard output stream with a different file-like object.
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.