Flashcards · Python · Free
Python flashcards, generated for you.
Example Python study cards to learn from right now — then generate a full set from your own notes (plus a practice quiz) and export to Quizlet or Anki. Free, no account needed.
Example Python flashcards
What is the difference between '==' and 'is' in Python?
'==' compares values (content equality), while 'is' compares object identity (same memory address). Example: [1,2] == [1,2] is True, but [1,2] is [1,2] is False.
What does a mutable default argument do, and why is it dangerous?
Mutable defaults (lists, dicts) are created once at function definition, not on each call. All calls share the same object. Use None and create a new object inside the function instead: def f(x=None): x = x or []
How do list slices work with negative indices?
Negative indices count from the end: list[-1] is the last element, list[-2] is second-to-last. In slicing, list[start:stop:step], negative indices work the same way. list[:-1] excludes the last element.
What is the difference between 'append()' and 'extend()' for lists?
append() adds a single element (or object) to the end. extend() iterates over an iterable and adds each element. Example: [1].append([2]) → [1, [2]]; [1].extend([2]) → [1, 2]
What does 'pass' do in Python?
pass is a null operation—when executed, nothing happens. Used as a placeholder in functions, classes, loops, or conditionals where syntax requires a body but no code is needed yet.
Explain variable scope: what is LEGB?
LEGB is the order Python searches for variables: Local → Enclosing (nonlocal) → Global → Built-in. Python stops at the first match. Use 'nonlocal' or 'global' keywords to modify outer-scope variables inside a function.
Why does 'x = x + 1' inside a function fail if x is global, but 'x[0] = 5' doesn't?
Assignment (x = ...) creates a local variable, so referencing x before assignment raises UnboundLocalError. Mutating x[0] doesn't reassign x itself, so it accesses the global x. Use 'global x' to reassign a global variable.
What is the difference between '*args' and '**kwargs'?
'*args' captures positional arguments as a tuple; '**kwargs' captures keyword arguments as a dictionary. Example: def f(*args, **kwargs): print(args, kwargs); f(1, 2, a=3, b=4) → (1, 2) {'a': 3, 'b': 4}
What does 'in' check for dictionaries, and how do you check values?
'in' checks if a key exists in a dictionary, not the value. Example: 'a' in {'a': 1} is True, but 1 in {'a': 1} is False. Use 'value in dict.values()' to check for values.
Explain short-circuit evaluation with 'and' and 'or'.
'and' returns the first falsy value (or last value if all truthy); 'or' returns the first truthy value (or last if all falsy). They don't return bool—they return the actual object. Example: 0 or 'default' → 'default'; [] and 5 → []
Make your own Python study set
Flashcards for related topics
Studying Python to build with AI? MindloomHQ turns it into real skills — structured courses, agent projects, and certificates.
Explore MindloomHQ →