Variable
A named place that refers to a value; the name can be re-pointed at a new value.
A variable is a name bound to a value. It is not a box that remembers everything you put in it — reassigning the name simply points it at a new value, and the old one is gone unless another name still holds it.
See alsoValue·Assignment (=)·Name binding
Appears inValues and names
Value
A piece of data a program computes with — a number, some text, True or False.
Every value has a type that decides what you can do with it. Values are what expressions evaluate to and what variables refer to.
See alsoVariable·Data type
Appears inValues and names
Name binding
Attaching a name to a value with `=`; rebinding moves the name, it doesn't change the old value.
Binding a name with `=` makes it refer to a value. Binding it again moves the name to a new value; if you need the old one later, save it under another name first.
See alsoVariable·Assignment (=)·Aliasing
Appears inValues and names
Data type
The kind of a value (int, float, str, bool) — it decides which operations are allowed.
The type of a value, not how it looks, decides what an operator does: "3" + "4" joins text, while 3 + 4 adds numbers. The four core types a beginner meets are int, float, str, and bool.
See alsoInteger (int)·Floating-point (float)·String (str)·Boolean (bool)
Appears inNumbers have types: int vs float·Converting a float to an int
Integer (int)
A whole number with no fractional part, like 13 or -4.
Integers count things and index positions. In Python they have unlimited size (no overflow), unlike fixed-width integers in hardware.
See alsoFloating-point (float)·Floor division (//)·Overflow
Appears inNumbers have types: int vs float·Overflow
Floating-point (float)
A number with a fractional part, like 3.5 — stored in binary, so some values are approximate.
Floats represent fractional numbers but in binary, so values like 0.1 can't be stored exactly. That is why 0.1 + 0.2 isn't quite 0.3 and why you shouldn't compare floats with ==.
See alsoInteger (int)·True division (/)·Round-off error
Appears inNumbers have types: int vs float·Roundoff
String (str)
Text — a sequence of characters in quotes, like "racecar".
Strings are sequences you can index and slice, and they are immutable: "changing" a string actually makes a new one.
See alsoImmutable·Index·Slice
Appears inPalindrome check
Boolean (bool)
A value that is either True or False.
Booleans are what comparisons produce and what conditions test. In Python True and False also act as 1 and 0 numerically.
See alsoComparison·Truthiness·Boolean operator (and / or / not)
Appears inA comparison is a yes/no value·and / or / not
Operator
A symbol that combines values: + - * / // % ** for maths, == < > for comparison.
Operators act on values to produce new ones. Which operation happens depends on the operands' types and on precedence.
See alsoOperator precedence·Modulo (%)·Exponent (**)
Appears inOperator precedence: × before +
Expression
Any piece of code that evaluates to a value, like 2 + 3 or x > 0.
Expressions compute values; statements do things. A comparison like age >= 18 is an expression that evaluates to a Boolean.
See alsoValue·Operator·Comparison
Appears inOperator precedence: × before +
Operator precedence
The order operators run in: × and ÷ happen before + and −, regardless of left-to-right.
Python follows the usual maths order, not strict left-to-right, so 2 + 3 * 4 is 14, not 20. Parentheses override it when you mean the addition first.
See alsoOperator·Expression
Appears inOperator precedence: × before +
Floor division (//)
Division that throws away the remainder and returns a whole number.
7 // 2 is 3, not 3.5 — the fraction is discarded. Useful for counting whole groups; the wrong choice when you want an average.
See alsoTrue division (/)·Modulo (%)·Integer (int)
Appears inNumbers have types: int vs float
True division (/)
Division that keeps the fraction and returns a float.
7 / 2 is 3.5. A single slash always yields a float in Python, even when the numbers divide evenly.
See alsoFloor division (//)·Floating-point (float)
Appears inNumbers have types: int vs float
Modulo (%)
The remainder after division; it wraps values around (clock arithmetic, even/odd).
10 % 3 is 1. Modulo powers wrap-around (15 o'clock becomes 3), parity tests (n % 2 == 0 means even), and cycling through positions.
See alsoFloor division (//)·Overflow
Appears inModular arithmetic: wrapping around·Overflow·FizzBuzz
Exponent (**)
Raising to a power: 2 ** 3 is 8. In Python `^` is NOT power — it is bitwise XOR.
Use ** for powers. The `^` symbol many languages and spreadsheets use for powers is bitwise XOR in Python, so 2 ^ 3 silently gives 1.
See alsoOperator
Appears inPowers: ** not ^
Assignment (=)
Binds a value to a name. Not the same as == (which compares).
`=` stores a value in a name; `==` asks whether two values are equal. Using `=` where a condition expects `==` is a classic mix-up (in Python it's a syntax error).
See alsoComparison·Name binding
Appears inValues and names·A comparison is a yes/no value
Comparison
An operator like == or > that produces a Boolean (True/False) you can store and reuse.
A comparison is itself a value. age >= 18 evaluates to True or False, which you can keep in a variable or use directly in an `if`. Watch the boundary: > excludes the endpoint, >= includes it.
See alsoBoolean (bool)·Assignment (=)·Equality (==)
Appears inA comparison is a yes/no value·Roundoff
Equality (==)
Tests whether two values are equal; distinct from assignment (=).
== returns a Boolean. Beware: a list never equals True, and floats rarely compare equal exactly — prefer a tolerance for floats.
See alsoComparison·Truthiness·Round-off error
Appears inA comparison is a yes/no value·Roundoff
Boolean operator (and / or / not)
Combine conditions. `or` returns one of its operands, not always a tidy True/False.
`x == 1 or 2` is read as (x == 1) or 2 and yields the truthy 2 — not what you meant. Compare against each value in full: x == 1 or x == 2.
See alsoBoolean (bool)·Truthiness·Comparison
Appears inand / or / not
Truthiness
Any value can act as True or False in a condition; empty/zero/None are "falsy", the rest "truthy".
`if items:` asks whether items is truthy — a non-empty list is. But a list never equals True, so `if items == True:` quietly fails. The falsy values are 0, 0.0, "", [], {}, and None.
See alsoBoolean (bool)·None·Boolean operator (and / or / not)
Appears inTruthiness: what counts as true
Conditional (if)
Runs a block of code only when a condition is true.
An `if` chooses whether to run its block. Two separate `if`s are two independent decisions — both can run; use `if/else` (or `elif`) when only one should.
See alsoBranch·elif ladder·Boolean (bool)
Appears inChoosing one branch with if / else
Branch
One path through a conditional; if/elif/else pick exactly one to run.
Each arm of an if/elif/else is a branch. Exactly one runs, chosen top-to-bottom by the first true condition.
See alsoConditional (if)·elif ladder
Appears inChoosing one branch with if / else·The elif ladder: order matters
elif ladder
A chain of elifs; the first true branch wins, so the order of the tests is the logic.
Because the first matching branch wins and the rest are skipped, a grading ladder must test the strictest band first — put the loosest first and the strict branches become unreachable.
See alsoBranch·Conditional (if)
Appears inThe elif ladder: order matters
Loop
Code that repeats — a `for` over a sequence or a `while` on a condition.
Loops do the same work for each item or until a condition changes. Never delete from a list while looping over it — the positions shift under you.
See alsoIteration·range()·Accumulator
Appears inAdding up a list·Filtering a list
Iteration
One pass through a loop body.
Each time around the loop is an iteration, usually with the loop variable bound to the next item or index.
See alsoLoop·range()
Appears inAdding up a list·Linear search
range()
Produces integers to loop over; range(n) is 0..n-1 — the end is excluded.
range(len(nums)) yields each valid index. The exclusive end is a common off-by-one trap: range(5) stops at 4.
See alsoLoop·Index
Appears inLinear search·Decimal to binary
Accumulator
A variable that builds up a result across a loop — a running total or list.
Start it at a base (0 for a sum, [] for a list) and update it each pass with += or append. Using = instead of += overwrites instead of accumulating.
See alsoLoop·List
Appears inAdding up a list·Running maximum
Function
A named, reusable block that takes inputs and hands back a value with `return`.
A function packages an idea you can call. It opens its own scope, runs, and returns a value; a function that forgets to `return` hands back None.
See alsoParameter·Return value·Scope
Appears inFunctions: package an idea you can call
Parameter
A name in a function definition that receives an argument when the function is called.
Parameters are the function's inputs. Arguments fill them by position (left to right) unless you name them, so argument order matters.
See alsoArgument·Function
Appears inParameters: order matters
Argument
A value passed into a function call; positional arguments fill parameters left to right.
remaining(30, 100) binds the first parameter to 30 and the second to 100. Naming them — remaining(budget=100, spent=30) — makes the intent unmissable.
See alsoParameter·Function
Appears inParameters: order matters
Return value
What a function hands back; a function with no `return` hands back None.
`return` ends the function and gives a value to the caller. Computing the answer but forgetting to return it is a classic bug — the work happens, nothing comes out.
See alsoFunction·None
Appears inFunctions: package an idea you can call
Scope
The region where a name is visible; a function's locals live in its own frame.
Names created inside a function are local to it and vanish when it returns. The call stack tracks which frame's names are currently in view.
See alsoFunction·Call stack
Appears inFunctions: package an idea you can call
Call stack
The stack of active function frames; a call pushes a frame, a return pops it.
Each call adds a frame with its own locals; returning removes it. The stack is how a program remembers where to go back to, and how recursion keeps its many copies apart.
See alsoFunction·Scope·Recursion
Appears inFunctions: package an idea you can call
Recursion
A function that calls itself, each call a new frame, until a base case stops it.
Recursion solves a problem in terms of a smaller version of itself. Without a base case that stops the calls, it never ends.
See alsoFunction·Call stack
Appears inFunctions: package an idea you can call
List
An ordered, mutable collection of values, written [1, 2, 3].
Lists hold a sequence you can index, slice, and grow with append. Being mutable, a list can be changed through any name that shares it.
See alsoIndex·Slice·Mutable·Aliasing
Appears inFiltering a list·Sorting into two piles·Collecting rainwater
Index
A position in a sequence, starting at 0; s[0] is the first item.
Indices number items from 0. Negative indices count from the end (s[-1] is the last). Going past the end is an error.
See alsoList·Slice·range()
Appears inLinear search·Palindrome check
Slice
A sub-sequence like s[1:3]; the end index is excluded, and s[:] makes a copy.
Slicing reads part of a sequence without changing it. s[:] (or list(s)) is the idiom for copying a list so changes don't alias the original.
See alsoIndex·List·Aliasing
Appears inAliasing: two names, one list·Filtering a list
Mutable
Can be changed in place (lists, dicts); changes are seen through every name that shares it.
Mutating a list affects all of its aliases. That is powerful and dangerous: backup = scores doesn't copy, so changing scores changes backup too.
See alsoImmutable·Aliasing·List
Appears inAliasing: two names, one list·Sorting into two piles
Immutable
Cannot be changed in place (ints, strings, tuples); "changing" one makes a new value.
Immutable values are safe from aliasing surprises: name = name.upper() makes a new string and rebinds the name; the original is untouched.
See alsoMutable·String (str)·Integer (int)
Appears inAliasing: two names, one list
Aliasing
Two names pointing at the same object, so changing it through one is seen through the other.
Assignment binds another name to the same object; it does not copy. Equal object ids reveal the sharing. To get an independent copy of a list, slice it (scores[:]).
See alsoReference·Mutable·Slice
Appears inAliasing: two names, one list·Sorting into two piles
Reference
What a name actually holds — a pointer to an object, not a private copy.
Variables refer to objects. When two names reference one mutable object, they are aliases; this is the mechanism behind aliasing bugs.
See alsoAliasing·Mutable
Appears inAliasing: two names, one list·Sorting into two piles
List comprehension
A one-expression loop that builds a list, like [n for n in nums if n > 10].
A comprehension is concise shorthand for a build-a-new-list loop. Python still runs it as a loop internally; the finished list appears at the end.
See alsoList·Loop
Appears inFiltering a list
None
Python's "no value"; what a function returns when it has no `return`.
None is a real value meaning "nothing here". It is falsy, and it is what you get back from a function that computed something but forgot to return it.
See alsoTruthiness·Return value
Appears inFunctions: package an idea you can call·Truthiness: what counts as true
Syntax error
Code the interpreter can't parse at all, so it never runs (e.g. `if x = 5`).
A syntax error is caught before the program runs. It differs from a logic bug, where the code runs fine but produces the wrong answer.
See alsoAssignment (=)
Sentinel value
A stand-in value (like -1 for "not found") that can't be mistaken for a real answer.
Linear search starts found at -1: no real index is negative, so -1 unambiguously means "not found yet".
See alsoIndex
Appears inLinear search