Cheat Sheets

Python Interview Questions Cheat Sheet: Mutability, GIL, Decorators & Scope

By ArpaNeuro Team September 24, 2026
Python interview cheat sheet

Python interviews probe mutability (why sort vs sorted), names vs objects, the GIL (CPU-bound vs I/O), decorators, and generators. Be ready to explain is vs ==, default-argument traps, and what a list comprehension does. Web roles add WSGI/ASGI and SQL — still start from the language.

This Python cheat sheet is written for people searching for a fast, accurate reference: students, junior developers, and teams shipping production software. Pin it, copy the snippets, and come back when syntax slips.

Quick reference

  • Mutable: lists, dicts, sets. Immutable: str, tuple, frozenset, numbers.
  • is vs ==: is identity. == equality. Interned small ints are a trap in demos.
  • LEGB: Local, Enclosing, Global, Built-in. global / nonlocal to assign outward.
  • Decorator: A callable that wraps a function. @wraps to keep __name__.
  • Generator: yield produces lazy iterators. yield from delegates.
  • GIL: One bytecode thread at a time in CPython. I/O releases it; CPU-bound needs multiprocessing or native extensions.
  • comprehension: Builds a collection. A generator expression (x for x in xs) is lazy.
  • with: Context managers (open, locks). __enter__/__exit__ or @contextmanager.

Copy-paste examples

Decorator and a generator

Be ready to write both by hand. Mention functools.wraps unprompted if you can.

from functools import wraps

def once(fn):
    seen = {'done': False, 'value': None}
    @wraps(fn)
    def wrapper(*args, **kwargs):
        if not seen['done']:
            seen['value'] = fn(*args, **kwargs)
            seen['done'] = True
        return seen['value']
    return wrapper

def chunks(xs, n):
    buf = []
    for x in xs:
        buf.append(x)
        if len(buf) == n:
            yield buf
            buf = []
    if buf:
        yield buf

Common mistakes

  • Saying the GIL means Python cannot do concurrency — threads still help I/O.
  • Confusing shallow copy with deepcopy in an interview whiteboard.
  • Writing except: (bare) as the error-handling answer.
  • Cannot explain why def f(x=[]) is a bug.

FAQ

  1. list.sort vs sorted? sort mutates and returns None. sorted returns a new list. Interviewers watch whether you use the return value.
  1. What is a generator used for? Streaming large data without loading it all. Pipelines of iterators. range in Python 3 is this idea.
  1. How do you speed up Python? Profile first. Then algorithms, PyPy/C extensions, numpy, or move hot loops off the GIL. Not “rewrite in Java” as the first answer.

Related Python cheat sheets

Build with this stack

When a cheat sheet is not enough — you need a production app, a student FYP, or a custom dashboard — ArpaNeuro builds custom web development and also sells ready-made source code. Request a quote and tell us the stack.

Browse software development services or the source code marketplace if you want a working codebase instead of starting from a blank file.

← All Articles Get a Quote →