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 (whether they're the same object in memory). Example: `[1,2] == [1,2]` is True, but `[1,2] is [1,2]` is False.
Why does `x = [1,2,3]; y = x; y.append(4)` change both x and y?
Lists are mutable and passed by reference. `y = x` makes y point to the same list object, not a copy. To create a copy, use `y = x.copy()` or `y = x[:]`.
What does a mutable default argument in a function do?
It persists across function calls. Example: `def f(lst=[]):` creates one list object reused every call. Fix: use `def f(lst=None):` and initialize inside. This is a common gotcha.
What is the difference between `range(5)` and `list(range(5))`?
`range(5)` is a lazy range object (doesn't store all values). `list(range(5))` converts it to `[0, 1, 2, 3, 4]`. Use range in loops for efficiency.
How does Python's scoping work with the `LEGB` rule?
Variable lookup order: Local → Enclosing (closure) → Global → Built-in. Use `global` or `nonlocal` keywords to modify variables from outer scopes inside a function.
What's the difference between `None`, `False`, and `0` in boolean context?
All are falsy, but they're distinct objects. `None is None` is True, `None == False` is False, `0 == False` is True. Use `is None` to check for None specifically.
What does unpacking with `*args` and `**kwargs` do?
`*args` collects positional arguments into a tuple. `**kwargs` collects keyword arguments into a dict. Example: `def f(*args, **kwargs):` accepts any arguments.
Why does `for i in range(len(lst)):` often indicate non-Pythonic code?
Prefer `for item in lst:` for simple iteration or `for i, item in enumerate(lst):` if you need the index. Direct iteration is cleaner and faster.
What's the gotcha with list comprehensions and variable scope?
List comprehension variables are scoped locally in Python 3 (unlike loops). Also, comprehensions evaluate conditions left-to-right: `[x for x in range(5) if x > 2]` creates a fresh scope, not overwriting outer `x`.
How do `lambda` functions differ from regular functions?
`lambda` creates anonymous, single-expression functions. Cannot contain statements, docstrings, or multiple lines. Use for short callbacks: `sorted(lst, key=lambda x: x[1])`.
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 →