Languages

Python interview questions

Beta

The Python interviewers expect: data model, comprehensions, generators, typing and the standard library.

80 questions · 40 theory · 40 coding

Subtopics

  • Data types & mutability7
  • Lists, dicts, sets & comprehensions8
  • Functions, closures & decorators8
  • Iterators & generators8
  • Classes, dataclasses & dunder methods7
  • Exceptions & context managers6
  • Modules, packages & imports6
  • Type hints & typing6
  • async/await & asyncio6
  • The GIL, threads & multiprocessing6
  • String formatting & encoding6
  • Testing with pytest6

Sample questions

  • CodingJuniorasync/await & asyncio

    Write an async function double_later(x) that does await asyncio.sleep(0) (a no-op await, just to make it a real coroutine that yields control) and then returns x * 2. Then write entryPoint(numbers) that runs double_later concurrently for every

  • TheoryJuniorasync/await & asyncio

    What does defining a function with async def actually create? If you write result = my_coro_func() but never await it, what happens (or does not happen), and what does await do at the point it appears in the code?

  • CodingJuniorClasses, dataclasses & dunder methods

    Write a class Point with __init__(self, x, y), a dunder method __eq__ that treats two points as equal when their x and y match, and a dunder method __add__ that returns a new Point whose coordinates are the sums. Then write entryPoint(a, b), where a and

  • TheoryJuniorClasses, dataclasses & dunder methods

    Explain the difference between a class attribute and an instance attribute in Python. What goes wrong if a class attribute is a mutable object such as a list, and how do you avoid the problem?

  • CodingJuniorData types & mutability

    Write entryPoint(point, dx, dy) where point is a two-element list [x, y]. Return a list of two items: the moved point [x + dx, y + dy] and the original point exactly as it was passed in. The input list must not be modified.

  • CodingJuniorData types & mutability

    Write entryPoint(rows, cols, fill, updates) that builds a grid of rows rows and cols columns where every cell starts as fill, then applies each update [r, c, value] in order, and returns the grid as a list of row lists. Updates that fall outside the grid are ignored.