1/70
Vocabulary flashcards covering Python core concepts from the lecture notes.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Built-in Python function that outputs text to the console.
string
A sequence of characters defined with quotes; can use single or double quotes in Python.
quotes (single/double)
Strings can be defined with either single or double quotes in Python.
escape character
Backslash to include special characters inside strings (e.g., escaping quotes).
None
Python's absence-of-value marker; represented by the None keyword.
NoneType
The type of the None value.
dynamic typing
Python allows variable types to change over time.
static typing
Variable types are fixed; common in languages like Java and C++. Specifically contrasted with Python's dynamic typing.
type conversion
Changing a value from one type to another (e.g., int('10') -> 10, float(3)).
int()
Converts a value to an integer; truncates decimals.
float()
Converts a value to a floating point number.
bool
Boolean type; values are True or False.
NoneType
The type that represents the absence of a value (None).
type()
Built-in function that returns the data type of a value.
arithmetic operators
floor division
Operator //; divides and rounds down to an integer.
modulus
Operator %; returns the remainder after division.
exponent
Operator **; raises a number to a power.
shorthand operators
PEMDAS
Order of operations: parentheses, exponents, multiplication/division, addition/subtraction.
execution order
Code runs top-to-bottom unless control structures change flow.
list
Mutable, ordered collection of items; denoted with [ … ].
tuple
Immutable, ordered collection; denoted with ( … ).
dictionary
Key-value mapping; denoted with { key: value }.
set
Unordered collection of unique elements; created with set() or braces.
mutable vs immutable
Mutable (lists, dicts) can change; immutable (strings, tuples) cannot.
slice
Subsequence extraction using start:end:step notation.
negative indexing
Accessing elements from the end using negative indices (e.g., -1 for last element).
range
Function to generate a sequence of numbers for loops; end is exclusive.
index
Position of an element in a sequence; zero-based indexing.
len()
Returns the length of a sequence (string, list, etc.).
string concatenation
Joining strings using the + operator.
substring
A portion of a string obtained via slicing.
first n characters
s[:n] returns the first n characters of s.
last n characters
s[-n:] returns the last n characters of s.
string immutability
Strings cannot be modified in place; operations return new strings.
list append
Add an element to the end of a list.
list pop
Remove and return the last element; can specify index to remove.
in operator
Membership test; x in list/dict/set checks presence.
dictionary keys
Unique keys in a dictionary; used to access values.
dictionary values
Values stored in a dictionary; accessed via dict.values().
dictionary items
Key-value pairs; accessed via dict.items().
try/except
Error handling structure to catch and handle exceptions.
ValueError
Error raised when an operation receives an argument of the right type but inappropriate value.
ZeroDivisionError
Error raised when dividing by zero.
split
String method to split a string into a list using a delimiter.
read input
input() reads a line from standard input as a string.
parse input
Splitting a string (e.g., by comma) to convert into data structures.
read integers
Read a line, split by delimiter, convert each piece to int.
exception handling specificity
You can have specific except blocks (e.g., ValueError) and a generic one.
default argument
A function parameter with a default value; optional when calling the function.
type hints
Optional annotations declaring expected parameter and return types.
NoneType in hints
When a function returns nothing, the annotated return type can be None.
if statement
Conditional execution block; runs when the condition is true.
elif
Else-if branch in Python; additional condition checks.
else
Fallback block executed if previous conditions were false.
comparison operators
Operators like ==, !=,
logical operators
And, or, not; combine boolean expressions.
truthy/falsy
Truthiness: non-false values evaluate to True; falsy values evaluate to False.
default value order
Non-default parameters must come before default ones in function definitions.
for loop
Iterates over a sequence or range; uses range() for numeric ranges.
while loop
Repeats while a condition is true; requires careful increment to avoid infinite loops.
break
Terminate the nearest enclosing loop immediately.
continue
Skip the rest of the current loop iteration and continue.
pass
No-op placeholder; allows empty blocks without errors.
substring slicing rules
End index is non-inclusive; s[start:end] yields characters from start up to end-1.
reverse with slicing
Use [::-1] to reverse a string or sequence.
default parameter order rule
If a parameter has a default value, all following parameters must also have defaults.
split vs join
Split creates a list from a string; join combines a list of strings into one string.
enumerating dictionaries
Using for key in dict iterates keys; dict.items() yields (key, value) pairs.
importance of indentation
Indentation defines code blocks in Python; incorrect indentation causes errors.