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.

MediumTechnical
20 practiced

For an in-memory dataset you're processing repeatedly, compare storing it as a list of dicts (row-oriented) versus a dict of lists or tuple-of-arrays (column-oriented). What changes about memory layout, CPU cache behavior, and which operations get faster or slower?

HardTechnical
18 practiced

Implement a thread-safe LRU cache decorator in Python without using functools.lru_cache (you may use threading primitives). The decorator should accept a maxsize and be safe for concurrent access by multiple threads. Discuss complexity and potential contention points.

HardTechnical
22 practiced

Write a decorator that works both as @retry (no parentheses) and as @retry(max_attempts=5) (called with arguments). What makes this ambiguous case hard, and how do you detect which form was used?

EasyTechnical
26 practiced

What does if __name__ == '__main__': actually do in Python? Show a small script that behaves differently when run directly versus imported as a module, and give a real reason you'd use this idiom.

MediumTechnical
24 practiced

You have CPU-bound preprocessing that's become a bottleneck in a Python pipeline. Walk through your decision process: threading, multiprocessing, or asyncio, and why. Then say how your answer changes if the bottleneck were I/O-bound instead (say, many blocking network calls) and you needed to run them concurrently without a full rewrite.

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.