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.

MediumTechnical
20 practiced

Explain Python's LEGB scope resolution (Local, Enclosing, Global, Built-in). Write a nested function example that shows when you need the nonlocal keyword to modify an enclosing variable.

MediumTechnical
22 practiced

Python's sort is stable and adaptive (Timsort). What does stability actually buy you when you need to sort by more than one key, and what's the difference between list.sort() and the builtin sorted() in terms of what they return and when you'd choose one over the other?

EasyTechnical
20 practiced

Given a NumPy array a of shape (N, M), write Python code to compute a boolean mask of rows that contain any NaN using vectorized NumPy operations. Do not use Python loops.

MediumTechnical
23 practiced

Implement a memoize decorator that caches a function's return value keyed by its arguments, supports both positional and keyword arguments, and preserves the wrapped function's name and docstring. Why does functools.wraps matter here?

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.