PyMasterPython trace & interview prep
← All posts

10 Python Output Questions for Interview Preparation

Phone screens often allocate fifteen minutes to a Python snippet. You must read, trace, and explain aloud. Below are ten high-frequency patterns; practice each with a trace table before checking answers.

Pattern 1: Mutable defaults

def f(a, lst=[]):
    lst.append(a)
    return lst
print(f(1), f(2))

Output: [1] [1, 2]. The default list is shared across calls - a favorite Amazon and startup question.

Pattern 2: Closure in a loop

Late-binding closures trip candidates who expect each lambda to capture its own index. Trace what i equals when the function actually runs, not when it is created.

Patterns 3–10

Additional favorites include: list slice assignment, dictionary merge order, short-circuit booleans, integer identity for small ints, string interning quirks, generator exhaustion, try/except/else, and chained comparisons. Generate fresh variants on PyMaster's challenge page.

Practice this concept now - generate free problems instantly