PCEP key terms
PCEP · Get comfortable with the vocabulary.
- Interpreter
- Related: Variable, Keyword
A program that reads source code and executes it directly, translating it statement by statement at runtime rather than producing a separate compiled executable file first.
- Variable
- Related: Identifier, Type casting
A named reference that points to a value stored in memory. In Python you create one by assigning a value with the equals sign; no type declaration is required.
- Identifier
- Related: Variable, Keyword
A name you give to a variable, function, class, or module. It must start with a letter or underscore, may contain digits, and cannot be a keyword.
- Keyword
- Related: Identifier
A word reserved by the Python language for a fixed purpose, such as if, for, def, or None. You cannot use it as an identifier.
- Type casting
- Related: Exception, Variable
Converting a value from one data type to another using constructor functions such as int(), float(), or str(). Some conversions succeed silently while others raise an error at runtime.
- Operator precedence
- Related: Modulo operator, Floor division
The rules that decide which operator in an expression is evaluated first. Multiplication and division bind tighter than addition and subtraction, and parentheses override the default order.
- Floor division
- Related: Modulo operator, Operator precedence
The // operator, which divides two numbers and rounds the result down to the nearest whole number. With negative operands it rounds toward negative infinity, not toward zero.
- Modulo operator
- Related: Floor division
The % operator, which returns the remainder left after integer division. It is often used to test whether a number is even or odd.
- Truthiness
- Related: if-elif-else, while loop
The rule that any object can be tested as a condition. Empty collections, zero numbers, None, and empty strings count as false; most other values count as true.
- Escape sequence
A backslash followed by a character inside a string literal that stands for a special character, such as \n for a newline or \t for a tab.
- if-elif-else
- Related: Truthiness, while loop
A conditional block that runs one of several branches. Python tests each condition in order and executes only the first branch whose condition is true.
- while loop
- Related: for loop, break
A loop that repeats a block as long as its condition remains true. The condition is checked before each pass, so the body may never run at all.
- for loop
- Related: while loop, range()
A loop that visits each item of an iterable, such as a list, string, or range, and runs the body once per item.
- range()
- Related: for loop
A built-in function that produces a sequence of integers. It accepts a stop value, or start and stop, plus an optional step, and never includes the stop value.
- break
- Related: continue, Loop else clause
A statement that immediately ends the innermost loop, skipping any remaining iterations and the loop's else block if one is present.
- continue
- Related: break
A statement that skips the rest of the current loop iteration and jumps straight to the next one, without ending the loop itself.
- Loop else clause
- Related: break, while loop
An optional else block attached to a for or while loop. It runs only when the loop finished normally, not when the loop was exited with break.
- List
- Related: Tuple, Indexing
An ordered, mutable collection written with square brackets. It can hold items of mixed types, allows duplicates, and supports indexing, slicing, and many in-place methods.
- Tuple
- Related: List, Mutability
An ordered, immutable collection written with parentheses. Once created it cannot be changed, and it is often used to return several values from a function.
- Dictionary
- Related: Set, List
A mutable collection of key-value pairs written with curly braces. Keys must be unique and hashable; values can be any object. Lookup is done by key, not by position.
- Set
- Related: Dictionary, Mutability
An unordered, mutable collection of unique hashable items written with curly braces or set(). Duplicates are removed, and sets support union, intersection, and difference.
- Indexing
- Related: Slicing, List
Accessing a single item of a sequence by its position in square brackets. Python counts from zero, and negative indexes count backward from the end.
- Slicing
- Related: Indexing, List
Extracting a subsequence with the start:stop:step syntax. The start is included, the stop is excluded, and omitted values default to the beginning, the end, and a step of one.
- Mutability
- Related: List, Tuple
The property of an object that allows its contents to be changed after creation. Lists, dictionaries, and sets are mutable; tuples, strings, and numbers are not.
- List comprehension
- Related: List, for loop
A compact expression that builds a new list by applying an operation to each item of an iterable, optionally keeping only items that satisfy an if condition.
- Membership operator
- Related: Set, List
The in and not in operators, which test whether a value appears in a collection or a substring occurs in a string, returning True or False.
- Function definition (def)
- Related: Parameter and argument, Default parameter
A block introduced by the def keyword that names a function, lists its parameters, and contains the code that runs when the function is called.
- Parameter and argument
- Related: Function definition (def), Default parameter
A parameter is the name listed in a function definition; an argument is the actual value passed in when the function is called.
- Default parameter
- Related: Parameter and argument, Function definition (def)
A parameter given a value in the function definition. If the caller omits that argument the default is used; defaults must come after parameters that have none.
- Scope
- Related: Function definition (def)
The region of a program where a name can be accessed. Python resolves names through local, enclosing, global, and built-in scopes, in that order.
- Exception
- Related: try-except-finally, raise statement
An event that interrupts normal execution, such as dividing by zero or converting an invalid string. Unhandled exceptions stop the program and print a traceback.
- try-except-finally
- Related: Exception, raise statement
A block for handling errors: try holds risky code, except catches matching exceptions, and the optional finally always runs whether or not an error occurred.
- raise statement
- Related: Exception, try-except-finally
A statement that deliberately triggers an exception, either re-raising the current one or creating a new one with a message.
- open()
- Related: File mode, with statement
A built-in function that opens a file and returns a file object used for reading or writing. It takes a path plus an optional mode and encoding.
- File mode
- Related: open(), with statement
A short string passed to open() that says how the file is used: r for reading, w for writing and truncating, a for appending, b for binary, + for updating.
- with statement
- Related: open(), File mode
A context manager block that opens a file, runs its body, and closes the file automatically afterwards, even if an exception is raised inside.
- import statement
- Related: from-import statement, __name__ guard
The statement that loads a module and binds it to a name, giving access to its functions, classes, and variables through dot notation.
- from-import statement
- Related: import statement
A form of import that brings specific names from a module directly into the current namespace, optionally renaming them with the as keyword.
- __name__ guard
- Related: import statement
The idiom if name == "main": used to run code only when the file is executed directly, not when it is imported as a module.