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.

HardTechnical
18 practiced

Implement a safe file-based lock in Python usable across processes on the same machine. The API should support acquire(timeout) and release, and avoid race conditions if two processes try to create the lock simultaneously. Discuss platform differences (Unix vs Windows).

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
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.

HardTechnical
22 practiced

Built-in operations like list.append or dict.setitem won't crash under concurrent access from multiple threads, thanks to the GIL. But that doesn't mean they're safe for every use case. Which common list and dict operations are atomic in this sense, and where does that guarantee stop protecting you?

HardTechnical
18 practiced

Given a shared counter incremented by several threads in a tight loop with count += 1, why does the final count come out wrong even though the GIL exists? Provide a corrected, efficient version, and explain which Python operations are actually safe to share across threads without a lock and which aren't.

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.