Skip to content

Python Basics

Glossary

122 terms from Python Basics, in plain words, each with the chapter that teaches it.

#

**
The operator that raises a number to a power. `7 ** 2` means 7 times 7, which is 49.
+=
A shortcut that changes a variable using its own current value. `stock += 5` means `stock = stock + 5`, and `total += price` adds each price to a running total.
.get()
A dictionary method that returns the value for a key, or `None` (or a default you give) if the key is missing. It avoids a `KeyError` and is used for counting.
.items()
Dictionary methods for looping. `.items()` gives each key-value pair, and `.values()` gives only the values, handy with `sum`.
.sort()
A list method that reorders the list itself and gives back nothing. Unlike `sorted()`, it does not make a new list.
//
The operator that divides and keeps only the whole-number part. `20 // 6` is 3, the number of full boxes of 6 that 20 mugs can fill.
==
Operators that compare two values and give `True` or `False`. `==` tests for equal, whereas a single `=` stores a value in a variable.

A

and, or, not
Words that combine conditions. `and` needs both sides true, `or` needs at least one, and `not` flips true to false.
append
A list method that adds an item to the end of the list, such as adding each product to `cart`.
Argument
The actual value you pass to a function when you call it. In `greet("Ada")`, `"Ada"` is the argument.
Assignment
Attaching a name to a value with a single `=`, as in `price = 8.50`. It is not a math equation, and assigning again moves the name to a new value.
Attribute
A value stored inside another value, read with a dot and no parentheses. For a date, `sale_day.year` gives 2026.

B

Block
A group of indented lines that belong together under a line ending in a colon, such as the lines under an `if`, a loop or a `def`.
Bool
The type with only two values, `True` and `False`, written with capital letters. It is named after the mathematician George Boole.
Boolean expression
A test that works out to `True` or `False`, such as `age >= 18`. `if` and `while` use these to decide what to do.
break
A keyword that leaves a loop immediately. It is often used inside `while True:` to stop when the user types `done`.
Built-in
Something that comes with Python and is ready to use without importing, such as `print`, `len` and `input`.

C

Call
Running a function by writing its name followed by parentheses, such as `greet()`. Defining a function only stores it, and calling it makes it run.
Chaining
Calling several methods in a row on one value, as in `name.strip().title()`. Python works from left to right, using each result for the next method.
Character
A single letter, digit, space or symbol in a string. `len("coffee")` counts 6 characters.
Class
Python's name for a type of value, which is why `type(3)` shows `<class 'int'>`. Designing your own classes is covered in the next book.
Code editor
A program for writing code that colors it to make it easier to read and underlines mistakes before the program is run. VS Code is a popular free example.
Comment
A note for humans written after a `#` sign. Python ignores it, and good comments explain why code does something.
Comparison
An expression that asks a yes-or-no question about two values, such as `stock > 0`. The answer is always `True` or `False`.
Constant (capitalised name)
A name written in capitals, like `TAX_RATE`, that by convention marks a value which should never change. Functions can read it from the top of the file.
continue
A keyword that skips the rest of the current pass of a loop and jumps to the next one.
Counting pattern
Using a dict to count things with `counts[x] = counts.get(x, 0) + 1`, so a new key starts from 0. Adding an amount instead of 1 gives totals per key.
CSV
A plain text file with one record per line and commas between the values. The expense tracker stores lines like `2026-10-21,postage,12.50` in `expenses.csv`.

D

date
A type from the `datetime` module that represents a calendar day. You can read `.year`, `.month` and `.day`, and subtract two dates to get the gap.
Debugging
Finding and fixing the cause of a wrong result in a program. A simple technique is to add a temporary `print` of a variable to see what is happening, then remove it once the bug is fixed.
Decimal
An exact decimal number type from the `decimal` module, good for money. Create it from text, as in `Decimal("0.10")`, so `Decimal("0.10") + Decimal("0.20")` gives exactly `0.30`.
def
The keyword that creates a function: `def`, a name, parentheses and a colon, followed by an indented body. Defining it stores the code but does not run it.
Default value
A value given to a parameter in the `def` line with `=`, used when the caller leaves that argument out. In `price_with_tax(price, rate=0.2)`, 0.2 is the default rate.
del
A keyword that removes a key-value pair from a dictionary, as in `del prices["notebook"]`.
Dict
A collection of key-value pairs written in curly braces. You look a value up by its key, such as `prices["mug"]` giving 8.50.
Docstring
A short description in triple quotes as the first line inside a function. VS Code shows it when you hover over the function's name.

E

elif
Short for "else if", it adds another condition between `if` and `else`. Python runs the first block whose condition is true and skips the rest.
else
The part of an `if` statement that runs when the condition is false, and the fallback after all `elif` tests fail.
Encoding
The rule for storing letters and symbols as numbers in a file. UTF-8 handles every language, so files are usually opened with `encoding="utf-8"` to make text save and load the same way on every computer.
enumerate
A built-in function that gives each item together with its number in a loop. `start=1` makes the count begin at 1.
Error message
The text Python shows when it cannot understand or run your code. Read it from the bottom up, because the last line names the problem.
Exception
An error that stops the program unless it is caught. Python raises one when it cannot carry on, such as `ValueError` for `int("ten")`.

F

f-string
A string with an `f` before the opening quote that fills in values written inside curly braces. For example, `f"Hi {name}"` puts the value of `name` in the text.
File
A named place on the disk where data is saved so it survives after the program ends, such as `orders.txt`.
FileNotFoundError
The exception raised when you open a file that does not exist. The expense tracker catches it to start with an empty list.
Float
A number with a decimal point, such as 4.5. Floats cannot store every decimal exactly, so `0.1 + 0.2` gives `0.30000000000000004`.
for loop
A loop that runs the same indented lines once for each item in a list, string, range or other collection. In `for item in cart:`, `item` holds each value in turn.
Format code
A short code after a colon inside an f-string's braces that controls how a value is shown. `.2f` gives two decimal places, and `:<12` and `:>8` pad and align text.
from ... import
A way to import one tool from a module so you can use it without the module name, as in `from random import randint`.
Function
A named piece of code that does a job when you call it, such as `print` or your own `greet`. It can take arguments and hand back a result.

I

if statement
An instruction that runs its indented lines only when its condition is true. It can be extended with `elif` and `else`.
import
A statement that brings a module's tools into your program, such as `import random`. You then write the module name, a dot and the tool.
in
An operator that checks whether something is inside text, a list, a set or a dictionary's keys. `not in` is its opposite.
Indentation
The spaces at the start of a line, conventionally four in Python, that show which block the line belongs to. Inconsistent indentation causes an `IndentationError`.
IndentationError
The error Python raises when the indentation of lines is inconsistent.
Index
The position number of a character in a string or an item in a list. Counting starts at 0, and negative numbers count from the end.
IndexError
The exception raised when you ask for a list or string position that does not exist, such as `code[10]` on a 6-character string.
Infinite loop
A loop whose condition never becomes false, so it never stops by itself. Press Ctrl+C in the terminal to stop the program.
input()
A built-in function that shows a message, waits for the user to type and press Enter, and gives back what they typed. It always returns text, so convert it with `int()` or `float()` for math.
insert, remove, pop
List methods that change the list itself. `insert(i, x)` adds at a position, `remove(x)` deletes the first matching value, and `pop()` removes the last item and gives it back.
Int
A whole number such as 3 or -20. Calling `int("3")` converts text into an int.
Interpreter
The program that reads your Python file and carries out each line from top to bottom.
InvalidOperation
The exception from the `decimal` module raised when text such as `ten` or `nan` cannot be turned into a `Decimal`.

J

join
A string method that glues a list of strings into one string, putting the text before the dot between each pair, as in `", ".join(products)`. It is the opposite of `split`.

K

Key
The name you look up in a dictionary. Each key appears once and has a value stored under it.
KeyError
The exception raised when you look up a dictionary key that is not there, such as `prices["lamp"]`.
Keyword argument
An argument given by writing the parameter's name, such as `rate=0.05` or `reverse=True`. Their order no longer matters.

L

len()
A built-in function that gives the number of characters in a string or items in a list or dict.
List
An ordered collection of values in square brackets, like `cart`. Unlike a string, a list can be changed after it is made.
Local variable
A variable created inside a function that exists only while the function runs. Code outside cannot see it, so use `return` to get a value out.
Loop
Code that repeats. A `for` loop runs once per item, and a `while` loop runs while a condition is true.

M

match and case
A tidy alternative to a long `if`/`elif` chain, available in Python 3.10 and later. Each `case` names one value to match, and `case _:` catches everything else.
math
A module that adds calculator tools such as `math.sqrt`, `math.ceil`, `math.floor` and `math.pi`. `ceil` rounds up, which is handy for working out boxes needed.
max, min, sum, sorted
Built-in functions for a collection of values. They give the largest, smallest, total, and a new list in order. `sorted` leaves the original alone, unlike the `.sort()` method.
Method
A function that belongs to a value, called with a dot, such as `name.upper()`. String methods return a new string rather than changing the original.
Mode
The choice in `open()` of what you want to do with a file: `"w"` writes and empties it, `"a"` appends to the end, and `"r"` reads, which is the default.
Module
A file of ready-made Python code that you can import, usually about one subject, such as `random` or `datetime`. Any of your own `.py` files in the same folder can be a module too.

N

NameError
The error raised when you use a name Python does not know, usually from a misspelled variable or from reaching a local variable outside its function.
None
A special value meaning "nothing". A function without a `return` gives back `None`, and `.get()` returns it for a missing key.

O

open()
A built-in function that opens a file, given its name and a mode. It is normally used with `with` so the file is closed automatically.
Operator
A symbol that performs a calculation or comparison, such as `+`, `*`, `==` or `in`.

P

Parameter
A name in a function's `def` line that receives a value when the function is called. In `greet(name)`, `name` is the parameter.
PATH
The list of places your computer looks for programs. Adding Python to it on Windows lets you start Python from any folder.
print()
A function that shows a value on the screen for a person to read. It does not give a value back to your code, unlike `return`.
Program
A list of instructions for a computer, written in a language such as Python and run from top to bottom.
Prompt
The `>>>` sign in the interactive shell that shows Python is waiting for you to type.
python3
The terminal command that starts Python. With a file name, as in `python3 hello.py`, it runs the file, and alone it opens the shell. Windows users type `python`.

Q

quantize
A `Decimal` method that rounds a number to the decimal places of another one. `Decimal("12.5").quantize(Decimal("0.01"))` gives `12.50`, rounded to cents.

R

raise
A keyword that makes your own code report an exception, such as `raise ValueError("Not enough stock")`.
random
A module for random numbers and choices, with tools like `randint`, `choice` and `shuffle`. Results differ on every run.
range()
A built-in function that produces a series of numbers, starting at 0 by default and stopping just before the number given. It is used to repeat a loop a set number of times.
REPL (shell)
The `>>>` prompt where each line you type runs at once and shows its result. It is good for trying small ideas, and you leave it with `exit()`.
Return
A keyword that hands a value back from a function to the code that called it and ends the function immediately. Without it, a function gives back `None`.
round()
A built-in function that rounds a number for calculating, as in `round(2.678, 2)` giving 2.68.
Running total
A variable that starts at 0 before a loop and has each item added to it inside the loop, as in `total += price`. The same pattern can count items.

S

Set
A collection of unique items with no order. It is useful for removing duplicates and for comparing groups with `&`, `|` and `-`.
Slice
A piece of a string or list taken with `text[start:stop]`. It starts at `start` and stops just before `stop`.
Snake case
The Python style of naming with lower-case words joined by underscores, like `order_total`.
Special characters
Characters inside a string that begin with a backslash. `\n` is a new line and `\t` is a tab, and `write()` needs `\n` at the end of each line.
split
A string method that cuts text into a list of pieces at the text you give it, or at spaces if you give nothing. `"coffee,mug".split(",")` gives `['coffee', 'mug']`.
Standard library
The collection of modules that comes with Python, covering things like random numbers, math and dates.
Statement
One instruction to Python, such as an `if` statement or a line that assigns a variable.
strftime
A date method that shows a date in a style you choose using `%` codes like `%Y`, `%m`, `%d` and `%B`. `isoformat()` and `fromisoformat()` convert to and from the `YYYY-MM-DD` form.
String
Text in quotes, such as `"mug"`. Strings cannot be changed once made, and string methods give back a new string.
String methods
Methods that tidy or test text. `strip` removes spaces from both ends, `upper`, `lower` and `title` change capitals, `replace` swaps text, and `startswith`, `endswith` and `isdigit` answer yes-or-no questions.
Syntax
The set of rules for how code must be written. Breaking them, such as leaving a parenthesis unclosed, causes a `SyntaxError`.
SyntaxError
The error raised when Python cannot understand the code, for example from a missing closing parenthesis, quote or colon.

T

Terminal
A window where you type commands instead of clicking. You use it to run Python files, for example Terminal on macOS or PowerShell on Windows.
Traceback
The report Python prints when an uncaught error stops the program. It shows where the error happened and how the program got there, and you read it from the bottom up.
Truthy and falsy
Values that count as true or false in a condition. Empty text, an empty list and `0` are falsy, and nearly everything else is truthy.
try and except
A way to catch errors. Risky code goes in `try:`, and an `except` block naming the error runs if it happens, so the program carries on instead of crashing.
Tuple
A small, fixed group of values written in parentheses, like `("mug", 8.50)`. It cannot be changed after it is made.
Type
The kind of a value, such as `int`, `float`, `str` or `bool`, which decides what you can do with it. The built-in `type()` function tells you a value's type.
Type conversion
Changing a value to another type by calling the type's name as a function, such as `int("3")`, `float("8.50")` or `str(25)`. It is needed because `input()` always gives text.
TypeError
The exception raised when you use the wrong type, such as `"Total: " + 25` or changing a tuple item.

U

Unpacking
Splitting a tuple or list into separate variables in one step, as in `name, price = ("mug", 8.50)`.

V

ValueError
The exception raised when a value has the right type but wrong content, such as `int("ten")`. It is also what `list.remove` raises when the item is missing.
Variable
A name tag attached to a value so you can use it later. `=` attaches the name, and assigning again moves the tag to a new value.
VS Code
Visual Studio Code, a free code editor from Microsoft. With its Python extension it colors code and underlines mistakes.

W

while loop
A loop that keeps running while its condition is true, checking before each pass. It suits cases where you only know when to stop, and it runs forever if nothing makes the condition false.
with
A keyword used with `open()` that closes the file automatically when its indented block ends, even if an error happens.

Z

ZeroDivisionError
The exception raised when you divide by zero.