Interview prep

Python Interview Questions

Python interviews mix language internals with practical data-structure work. Expect live coding plus questions about the standard library.

Questions and answers

01What is the difference between a list and a tuple in Python?

Lists are mutable and slightly heavier; tuples are immutable, hashable when their contents are hashable, and can therefore be used as dictionary keys. Interviewers usually follow up by asking where immutability helps — shared constants, cache keys and function defaults.

02How does Python manage memory?

CPython uses reference counting plus a cyclic garbage collector for reference cycles. Objects are freed as soon as their refcount hits zero, which is why holding a reference in a global or a closure is the usual cause of a leak.

03What are decorators and when would you use one?

A decorator is a callable that takes a function and returns a wrapped function. They are used for cross-cutting behaviour — timing, retries, caching, authorisation — without touching the wrapped function's body.

04Explain the GIL and how you work around it.

The Global Interpreter Lock allows only one thread to execute Python bytecode at a time. IO-bound work still benefits from threads or asyncio; CPU-bound work needs multiprocessing, native extensions or a different runtime.

05What is the difference between deep copy and shallow copy?

A shallow copy duplicates the outer container and shares references to the nested objects; a deep copy recursively duplicates everything. Mutating a nested list after a shallow copy is the classic bug this question probes.

How to answer these well

Interviewers are not grading recall — they are checking whether you've hit the failure mode the question describes. Anchor every answer to something you actually shipped or debugged with Python.

Say the trade-off out loud. "I'd use X here, but it costs Y under Z conditions" scores higher than a clean textbook definition every time.

Roles asking for Python

Related prep