InterviewStack.io LogoInterviewStack.io

Python Programming Questions

Python as an interview language: core syntax, data types and built-in collections, comprehensions, iterators and generators, idiomatic style, and the standard library, extending into data-oriented and automation use of the language and its common libraries. Covers writing correct, Pythonic code and reasoning about the language's semantics. The most heavily exercised language surface in this category across engineering and data roles.

EasyTechnical
24 practiced

What does the with statement actually do in Python, and why do context managers matter for resource cleanup? Sketch a minimal custom context manager for a resource that must always be closed, even if the block raises.

MediumTechnical
19 practiced

For list.append, list.pop(), list.pop(0), list.insert(0, x), and list.index(x), what is the time complexity of each and why? Then look at this snippet: a function that builds a list with repeated insert(0, ...) calls inside a loop, and another that does linear scans with in inside a loop. What's the actual complexity of each function, and how would you fix it?

HardTechnical
19 practiced

Design a caching decorator whose entries expire after a configurable TTL. What data structure backs the cache, how do you evict stale entries (lazily on access versus proactively), and what changes if you also need it to be thread-safe?

MediumTechnical
26 practiced

Why can a tuple be used as a dictionary key or set member while a list can't? Walk me through what makes an object hashable in Python, and what invariant must hold between hash and eq for a type to be safely usable as a key.

HardTechnical
31 practiced

Design a producer-consumer pipeline in Python where producers can outpace consumers. How do you apply backpressure so producers don't overwhelm consumers, using a bounded queue? Walk through both a threading-based version and an asyncio.Queue-based version, and the wake-up semantics involved (notify vs notify_all, or await put/get).

Unlock Full Question Bank

Get access to all Python Programming interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.