StudyToCert

All certifications / PCEP / Cheat sheet

PCEP PCEP-30-02 cheat sheet

Every exam tip and key term from the free PCEP lessons, by domain. Use your browser's Print to save it as a PDF.

Domain 1: Computer programming and Python fundamentals (18%)

Exam tips

Key terms

Source code
The human-readable program text you write, stored for Python in a plain-text .py file.
Compiler
A program that translates the whole source code into machine code ahead of time, producing a separate executable.
Interpreter
A program that reads and executes source code each time it runs; CPython is Python's reference interpreter.
Lexis
The vocabulary of a language: the valid words and symbols it recognises.
Syntax
The grammar rules for combining lexical elements into valid statements.
Semantics
The rules that decide whether a well-formed statement makes sense and what it means.
REPL
The interactive read-eval-print loop, shown by the >>> prompt, that runs each line as you type it.
Statement (instruction)
A single command the interpreter executes, normally one per line.
Keyword
A reserved word with fixed meaning, such as if, for or def, that cannot be used as an identifier.
Block (suite)
The group of indented statements belonging to a header line that ends with a colon.
Comment
Text after # to the end of the line, ignored by the interpreter.
IndentationError
The SyntaxError subclass raised when indentation is missing, unexpected or inconsistent.
Docstring
A string literal placed first in a module or function, kept as its documentation.
Literal
A value written directly in source code, whose form determines its type.
int
Python's integer type for whole numbers, with no fixed size limit.
float
Python's type for numbers with a fractional part or exponent, such as 2.5 or 1e-3.
Scientific notation
Float notation using e or E for a power of ten, as in 6.02e23; always produces a float.
bool
The Boolean type with values True and False, a subclass of int where True equals 1 and False equals 0.
str
Python's text type, written in single, double or triple quotes.
None
The single value of NoneType, meaning the absence of a value.
0b prefix
Marks a binary (base 2) integer literal, using only digits 0 and 1.
0o prefix
Marks an octal (base 8) integer literal, using digits 0 to 7.
0x prefix
Marks a hexadecimal (base 16) integer literal, using 0 to 9 and A to F.
bin(), oct(), hex()
Built-in functions that return a string representation of an integer in base 2, 8 or 16, with prefix.
int(text, base)
Converts a string of digits written in the given base into an int.
Bit
A single binary digit, 0 or 1; one hex digit represents four bits.
Variable
A name bound to a value by assignment; the value, not the name, has a type.
Identifier
Any name you create; it may use letters, digits and underscores, must not start with a digit and must not be a keyword.
Dynamic typing
The same name may refer to values of different types over time, with no declaration.
PEP 8
Python's official style guide, recommending snake_case for variables and functions, UPPER_CASE for constants and CapWords for classes.
Shadowing a built-in
Assigning to a built-in name such as list or str, which hides the original function in that scope.
NameError
The exception raised when code uses a name that has not been assigned.
True division (/)
Division that always returns a float, even for exact results like 4 / 2 = 2.0.
Floor division (//)
Division rounded down toward negative infinity; int with two ints, float otherwise.
Modulo (%)
The remainder paired with floor division, taking the sign of the divisor in Python.
Exponentiation (**)
Raises the left operand to the power of the right operand.
ZeroDivisionError
The exception raised when /, // or % has a divisor of zero.
Unary operator
An operator such as -x or +x that takes a single operand.
Concatenation
Joining two strings with +, producing a new string.
Replication
Repeating a string (or list) with * and an integer count.
Assignment operator (=)
Binds the name on the left to the value of the expression on the right.
Compound assignment
An operator such as += or //= that applies an operation and rebinds the variable to the result.
Chained assignment
Binding several names to one value in a single statement, as in a = b = 0.
Immutable
Unable to be changed in place; strings are immutable, so string operations build new strings.
Priority (precedence)
The rule deciding which operators are applied first in an expression.
Binding (associativity)
The order in which operators of equal priority are applied, usually left to right.
Right-to-left binding
The behaviour of **, so a ** b ** c means a ** (b ** c).
Parentheses
Brackets that force a sub-expression to be evaluated first, overriding priority.
Bitwise AND (&)
Produces 1 in each bit position where both operands have 1.
Bitwise OR (|)
Produces 1 in each bit position where at least one operand has 1.
Bitwise XOR (^)
Produces 1 in each bit position where the operands differ.
Bitwise NOT (~)
Flips all bits; for Python ints ~x equals -x - 1.
Shift (<< >>)
Moves bits left or right, multiplying or floor-dividing by powers of two.
Bit mask
A number used with &, | or ^ to test, set, clear or toggle chosen bits.
Relational operator
An operator such as ==, != or <= that compares two values and returns True or False.
Chained comparison
An expression such as 0 <= x < 5, equivalent to two comparisons joined by and.
Logical operator
and, or or not, used to combine or invert Boolean conditions.
Floating-point error
The small inaccuracy caused by storing decimal fractions in binary, as in 0.1 + 0.2.
Banker's rounding
round()'s rule of sending exact halves to the nearest even integer.
Tolerance comparison
Testing floats with abs(a - b) < small_value instead of ==.
Type casting
Explicitly converting a value to another type with a function such as int() or str().
Implicit conversion
Automatic promotion of an int to a float when the two are mixed in arithmetic.
Truncation
Dropping the fractional part toward zero, as int() does with floats.
Truthiness
The rule bool() uses: zero, empty and None are False; everything else is True.
ValueError
Raised when a conversion function gets an acceptable type but an unusable value, such as int("3.7").
TypeError
Raised when an operation or function receives a value of an unsupported type, such as int(None).
print()
Built-in that writes its arguments, converted to text, to the console, separated by sep and followed by end.
sep=
print() keyword argument giving the string inserted between arguments; the default is a single space.
end=
print() keyword argument giving the string printed after the last argument; the default is a newline.
input()
Built-in that reads one line from the user and always returns it as a string.
Prompt
The optional string passed to input() and shown before the user types.
Escape sequence
A backslash combination such as \n or \t that stands for a special character in a string.

Domain 2: Control flow: conditional blocks and loops (29%)

Exam tips

Key terms

if statement
Runs its indented block only when its condition is true.
elif
An extra condition tested only if all earlier conditions in the same statement were false.
else
The branch that runs when no earlier if or elif condition was true; it takes no condition.
Condition
Any expression whose truthiness decides whether a block runs.
Overlapping conditions
Conditions that can be true at the same time, which makes the order of elif branches significant.
Unreachable branch
A branch that can never run because an earlier condition always catches its cases.
Truthy
Any value that counts as true in a condition, such as non-zero numbers and non-empty collections.
Falsy
A value that counts as false: False, None, zero and empty strings or collections.
Short-circuit evaluation
and and or stop evaluating as soon as the result is known.
Logical operator
and, or or not, used to combine or invert conditions.
De Morgan's laws
Rules for negating combined conditions: not (a and b) equals not a or not b, and vice versa.
Nested conditional
An if statement inside the block of another conditional branch.
Indentation level
The column at which a line starts; it defines which block the line belongs to.
Dangling else
The question of which if an else belongs to; in Python, the one at the same indentation.
Flattening
Replacing nested ifs with and or with an elif chain to reduce indentation depth.
Logic error
A mistake that lets the program run but produces the wrong behaviour, such as a misplaced else.
pass
A keyword statement that does nothing, used where syntax requires a statement.
Stub
A placeholder function or block, often with a pass body, to be completed later.
Empty block error
IndentationError: expected an indented block, raised when a colon header has no body.
Compound statement
A statement such as if, for, while or def whose header ends in a colon and owns an indented block.
continue
Unlike pass, skips the rest of the current loop iteration.
while loop
A loop that repeats its body as long as its condition is true, checking before each iteration.
Iteration
One execution of a loop's body.
Loop condition
The expression checked before each iteration; the loop ends when it is falsy.
Infinite loop
A loop whose condition never becomes false, so it runs until interrupted or broken out of.
KeyboardInterrupt
The exception raised when the user presses Ctrl+C, used to stop a runaway program.
Sentinel value
A special input, such as quit, that tells a loop to stop.
range()
Built-in that produces integers from start up to but not including stop, moving by step.
Start
The first value of a range; 0 if omitted.
Stop
The boundary value, never included in the range.
Step
The amount added each time; negative steps count downward and 0 is not allowed.
Empty range
A range that produces no values, such as range(5, 2), so a loop over it runs zero times.
Loop variable
The name that takes each successive value in a for loop.
Iterable
An object whose items can be taken one at a time, such as a string, list, tuple, dict or range.
enumerate()
Built-in that yields (index, item) pairs while iterating.
Accumulator
A variable set before a loop and updated each iteration to build a total or result.
Immutable string
A string cannot be changed in place; loops build new strings instead.
range(len(seq))
A pattern that loops over the valid indexes of a sequence.
break
Immediately exits the innermost enclosing loop.
Innermost loop
The loop that most directly contains a statement; break and continue act only on it.
Flag variable
A Boolean set inside a loop to signal an event, such as found = True, checked later to stop an outer loop.
Early exit
Leaving a loop before its natural end, usually with break or return.
Loop else clause
A block after a for or while loop that runs only if the loop ended without break.
Normal termination
A loop ending because its condition became false or its items ran out.
Search loop
A loop that looks for an item and breaks when it finds it, often paired with else for the not-found case.
Nested loop
A loop placed inside the body of another loop; the inner loop completes fully for each outer iteration.
Outer loop
The enclosing loop, which controls how many times the inner loop is started.
Inner loop
The enclosed loop, which restarts from its beginning on every outer iteration.
Iteration count
The total number of times a loop body runs, found by multiplying or summing per outer pass.
Dependent range
An inner range whose bounds use the outer loop variable, so counts differ per outer pass.
Loop variable scope
In Python a for loop's variable remains defined after the loop, holding its last value.
Last assigned value
For range(n), the loop variable ends at n - 1, not n.
Counter variable
A variable a while loop updates itself; it usually ends one step past the last passing check.
NameError
Raised if you use a loop variable that was never assigned because the loop ran zero times.
Tracing
Recording each variable's value step by step to predict a program's output.

Domain 3: Data collections: tuples, dictionaries, lists and strings (25%)

Exam tips

Key terms

List
An ordered, mutable sequence of values written in square brackets, such as [1, 2, 3].
Index
An integer position used in square brackets to select one element, starting at 0 on the left.
Negative index
A position counted from the end of a sequence, where -1 is the last element.
Slice
The expression lst[start:stop:step], which returns a new list from start up to but not including stop.
Step
The third slice value, giving the stride between items; a negative step walks from right to left.
IndexError
The exception raised when an index falls outside the valid range of a sequence.
Method
A function attached to an object and called with dot notation, such as lst.append(x).
In-place operation
An operation that changes the existing object rather than creating a new one, typically returning None.
append()
A list method that adds a single item, which may itself be a list, to the end of the list.
insert()
A list method that places an item before the given position, shifting later items to the right.
remove()
A list method that deletes the first item equal to a given value and raises ValueError if none exists.
sorted()
A built-in function that returns a new sorted list from any iterable, leaving the original unchanged.
del
A statement that removes list items by index or slice, or deletes a variable name entirely.
Iteration
Visiting the items of a collection one at a time, typically with a for loop.
enumerate()
A built-in that yields (index, value) pairs so a loop can use both the position and the item.
Membership operator
The operators in and not in, which return True or False depending on whether a value is present.
List comprehension
An expression of the form [expr for item in iterable] that builds a new list in one line.
Filter condition
A trailing if in a comprehension that keeps only items for which the condition is true.
Conditional expression
The form a if condition else b, which evaluates to one of two values and can transform items in a comprehension.
Reference
The link from a variable name to an object in memory; names hold references, not the objects themselves.
Alias
A second name bound to the same object, so changes through one name are visible through the other.
Shallow copy
A new outer list containing references to the same inner objects, made by a[:], list(a) or a.copy().
Deep copy
A copy that also duplicates every nested object, made with copy.deepcopy().
Identity operator
The operator is, which returns True only when two names refer to the very same object.
Mutation
Changing an object in place, for example with append(), item assignment or +=, rather than creating a new object.
Nested list
A list that contains other lists as its items.
Matrix
A rectangular grid of values, represented in Python as a list of equally long row lists.
Row index
The first index in grid[r][c], selecting which inner list to use.
Column index
The second index in grid[r][c], selecting the element inside the chosen row.
Jagged list
A nested list whose inner lists have different lengths.
Nested loop
A loop inside another loop, used to visit every element of a two-dimensional structure.
Tuple
An ordered, immutable sequence, usually written with parentheses and commas, such as (3, 4).
Immutable
Unable to be changed after creation; any "change" produces a new object.
One-item tuple
A tuple with a single element, which requires a trailing comma, as in (5,).
Tuple packing
Creating a tuple by listing values separated by commas, as in t = 1, 2, 3.
Unpacking
Assigning the items of a sequence to several names at once, as in x, y = (3, 4).
Hashable
Able to serve as a dictionary key or set member; immutable values like tuples of immutable items qualify.
Dictionary
A mutable collection of key-value pairs, written as {key: value}, that is looked up by key rather than by position.
Key
The unique, hashable identifier used to store and retrieve a value in a dictionary.
Value
The data associated with a key; it can be of any type and need not be unique.
KeyError
The exception raised when indexing, deleting or popping a key that is not in the dictionary.
get()
A dictionary method that returns the value for a key, or None or a given default if the key is missing.
pop()
A dictionary method that removes a key and returns its value, raising KeyError if missing and no default is given.
update()
A dictionary method that adds or overwrites pairs from another dictionary.
keys()
A dictionary method returning a view of all keys in insertion order.
values()
A dictionary method returning a view of all values, which may contain duplicates.
items()
A dictionary method returning a view of (key, value) tuples, ideal for loops that need both.
View object
A live, iterable window onto a dictionary's keys, values or items that reflects later changes and cannot be indexed.
Membership test
Using in or not in on a dictionary to check whether a key, not a value, is present.
RuntimeError
The exception raised when a dictionary changes size while it is being iterated over.
String
An immutable sequence of Unicode characters, written in quotes, such as "Python".
Immutability
The property that a string's characters cannot be changed in place; changes create a new string.
Reverse slice
The slice s[::-1], which returns a new string with the characters in reverse order.
Lexicographic order
Dictionary-style comparison, character by character, where the first difference decides the result.
Code point
The number Unicode assigns to a character, returned by ord() and turned back into a character by chr().
Concatenation
Joining strings with + to create a new string.
Escape character
The backslash \, which gives the following character a special meaning inside a string literal.
Escape sequence
A backslash and a character, such as \n or \', that together stand for one character.
Newline
The line-break character written \n, which moves output to the next line.
Raw string
A literal prefixed with r, in which backslashes are kept as ordinary characters.
Triple-quoted string
A literal delimited by ''' or """ that can span several lines and contain both kinds of quotes.
Docstring
A string literal placed first in a function, class or module body to document it.
split()
Returns a list of substrings, splitting on whitespace by default or on a given separator.
join()
Called on a separator string, returns one string made by joining an iterable of strings.
strip()
Returns a copy with whitespace, or the given characters, removed from both ends.
find()
Returns the index of the first occurrence of a substring, or -1 if it is absent.
count()
Returns the number of non-overlapping occurrences of a substring.
replace()
Returns a copy with occurrences of one substring replaced by another, optionally limited in number.

Domain 4: Functions and exceptions (28%)

Exam tips

Key terms

Decomposition
Breaking a problem into smaller sub-problems, each solved by its own function.
Function
A named, reusable block of code that performs one task and can take arguments and return a value.
Abstraction
Using something through its name and interface without needing to know how it works inside.
Reuse
Writing code once and calling it from many places, so fixes and improvements apply everywhere.
Top-down design
Writing the main steps first as calls to functions, then implementing each function in turn.
Module
A Python file containing definitions that other code can bring in with import.
def
The keyword that starts a function definition, followed by the name, parameters in parentheses and a colon.
Function body
The indented block of statements that runs each time the function is called.
Invocation
Calling a function by writing its name followed by parentheses and any arguments.
Function object
The object created by a def statement, bound to the function's name and callable with parentheses.
NameError
The exception raised when code uses a name, such as a function, that has not been defined yet.
Not callable
The TypeError raised when parentheses are applied to an object, such as an integer, that is not a function.
return
A statement that ends a function and sends a value, or None if no value is given, back to the caller.
None
The single value of type NoneType, meaning "no value", returned by functions that do not return anything else.
Implicit return
The automatic return None that happens when a function reaches the end of its body.
Tuple return
Returning several comma-separated values, which Python packs into one tuple.
yield
A statement that makes a function a generator, handing out one value and pausing until the next is requested.
Generator
An object produced by calling a generator function, which yields values one at a time on demand.
Recursion
A technique in which a function solves a problem by calling itself on a smaller version of it.
Base case
The condition under which a recursive function returns directly without calling itself.
Recursive case
The branch that calls the function again with an argument closer to the base case.
Call stack
The stack of active function calls, each with its own local variables, waiting for results.
RecursionError
The exception, a subclass of RuntimeError, raised when the maximum recursion depth is exceeded.
Recursion limit
The maximum call depth Python allows, readable with sys.getrecursionlimit().
Parameter
A name listed in a function definition that receives a value when the function is called.
Argument
The actual value or expression supplied in a function call.
Positional argument
An argument matched to a parameter by its position in the call.
Keyword argument
An argument written as name=value and matched to the parameter with that name.
Mixed passing
A call that uses positional arguments followed by keyword arguments.
Binding
Associating a parameter name with the argument's object for the duration of a call.
Default value
A value given to a parameter in the definition, used when the caller supplies no argument for it.
Required parameter
A parameter with no default, which every call must supply.
Optional parameter
A parameter with a default value, which the caller may omit.
Definition time
The moment the def statement runs, when default values are evaluated once and the function object is created.
Mutable default
A default such as a list or dictionary that is shared by every call using it, so changes persist between calls.
None sentinel
Using None as a default and creating a fresh object inside the function when the argument is None.
Scope
The region of a program in which a name is visible and can be used.
Local variable
A name assigned inside a function, including its parameters, that exists only during that call.
Global variable
A name assigned at the top level of a module, visible to all functions in that file.
Shadowing
A local name hiding a global or built-in name with the same spelling inside a function.
global keyword
A declaration that makes assignments to a name inside a function affect the global variable.
UnboundLocalError
A NameError subclass raised when a local variable is read before it has been assigned in the function.
LEGB rule
The lookup order for names: local, enclosing, global, then built-in.
Exception
An object signalling a run-time error; also the name of the base class of all ordinary errors.
BaseException
The root class from which every Python exception inherits.
SystemExit
The exception raised by sys.exit() to end a program; it inherits directly from BaseException.
KeyboardInterrupt
The exception raised when the user presses Ctrl+C; it inherits directly from BaseException.
ArithmeticError
The base class for numeric errors, including ZeroDivisionError and OverflowError.
LookupError
The base class for invalid index or key errors, including IndexError and KeyError.
issubclass()
A built-in function that returns True if one class inherits from another or is the same class.
ZeroDivisionError
Raised when the divisor of /, // or % is zero; a subclass of ArithmeticError.
IndexError
Raised when a sequence index is outside the valid range; a subclass of LookupError.
KeyError
Raised when a dictionary key is not found; a subclass of LookupError.
TypeError
Raised when an operation is applied to a value of an unsuitable type.
ValueError
Raised when a value has the right type but an unsuitable content, such as int("abc").
Traceback
The report Python prints for an unhandled exception, ending with the exception type and message.
try block
The block of code that Python monitors for exceptions.
except clause
A handler that runs when the try block raises an exception of the named class or a subclass.
Bare except
An except: with no class, which catches every exception, including SystemExit and KeyboardInterrupt, and must come last.
except Exception
A handler that catches all ordinary errors while letting SystemExit and KeyboardInterrupt through.
else clause
An optional block after the except clauses that runs only if the try block raised nothing.
finally clause
An optional block that runs whether or not an exception occurred, used for clean-up.
First-match rule
Python runs only the first except clause, from top to bottom, whose class matches the raised exception.
Specific exception
A class low in the hierarchy, such as KeyError, that describes one precise kind of error.
General exception
A class high in the hierarchy, such as LookupError or Exception, that covers many kinds of error.
Unreachable branch
An except clause that can never run because an earlier clause already catches everything it would.
Ancestor class
A class further up the hierarchy from which a given exception class inherits.
Safety net
A final general handler, typically except Exception, that catches errors not handled by earlier clauses.
Propagation
The movement of an unhandled exception from a function back to its caller, and so on up the call chain.
Call chain
The sequence of function calls active at a moment, from the top-level code down to the current function.
raise
A statement that throws an exception deliberately, such as raise ValueError("bad input").
Re-raise
Using a bare raise inside an except block to let the current exception continue propagating.
Handler placement
The design choice of which level catches an exception, ideally the one that knows how to respond.
Study PCEP for free
Lessons, quizzes, exam simulations and hands-on labs.
Open the PCEP study plan