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 (memory address). Example: `[1,2] == [1,2]` is True, but `[1,2] is [1,2]` is False.
What does `None` represent in Python?
None is a singleton object representing the absence of a value. It is the default return value of functions that don't explicitly return anything. Use `is None` to check for it, not `== None`.
Why does this code produce unexpected output? `x = []; a = [x]*3; a[0].append(1); print(a)`
All three lists in `a` reference the same object. Output: `[[1], [1], [1]]`. Use list comprehension `[[] for _ in range(3)]` to create independent lists.
What is a mutable default argument and why is it dangerous?
A mutable object (list, dict) as a default parameter is created once and reused across function calls. Example: `def f(x=[]):` modifies the same list each call. Solution: use `None` and initialize inside the function.
Explain the output: `print(0.1 + 0.2 == 0.3)`
Prints `False` due to floating-point precision limits. 0.1 and 0.2 cannot be represented exactly in binary. Use `math.isclose()` or the `decimal` module for accurate comparisons.
What is the scope order Python uses to resolve variable names?
LEGB: Local, Enclosing (closure), Global, Built-in. Python searches in this order. Use `global` or `nonlocal` keywords to modify variables in outer scopes.
What does `*args` and `**kwargs` do in function definitions?
`*args` captures variable-length positional arguments as a tuple; `**kwargs` captures keyword arguments as a dictionary. Example: `def f(*args, **kwargs):` can accept any combination of arguments.
What is the difference between a shallow copy and a deep copy?
Shallow copy (`.copy()` or slicing) duplicates the container but references the same nested objects. Deep copy (`copy.deepcopy()`) recursively copies all nested objects. Matters for nested lists/dicts.
How does list slicing with negative indices work? What is `lst[-1:-3:-1]`?
`lst[-1:-3:-1]` starts at the last element, goes backward with step -1, and stops before index -3. For `lst=[0,1,2,3,4]`, it returns `[4, 3]`.
Why does `for i in range(3)` work but `for i in 3` raises TypeError?
`range()` returns an iterable object; integers are not iterable. Iterables implement the `__iter__()` method. Use `range(n)` to loop n times, not the integer itself.
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 →