JobsPing

Python interview practice

Covers data structures, generators, decorators, typing, async. Questions are written for real interviews at junior, mid and senior level.

Start a Python practice test

15 multiple-choice questions · 15 minutes · instant score with explanations

Sample Python interview questions

Three questions from the bank, with answers. The practice test draws different ones each time.

Question 1 · async · junior

What is the output and approximate runtime behavior of `main()`?

import asyncio

async def task_one():
    await asyncio.sleep(2)
    return 1

async def task_two():
    await asyncio.sleep(1)
    return 2

async def main():
    results = await asyncio.gather(task_one(), task_two())
    print(results)
  1. A.[1, 2] after approximately 2 seconds
  2. B.[1, 2] after approximately 3 seconds
  3. C.It raises a TimeoutError
  4. D.[2, 1] after approximately 2 seconds
Show answer

A. [1, 2] after approximately 2 seconds

asyncio.gather() runs multiple coroutines concurrently and returns a list of their results in the order they were passed. Since task_two takes 1 second and task_one takes 2 seconds, they run concurrently, finishing in about 2 seconds total. A common trap is thinking gather runs them sequentially.

Question 2 · typing · junior

What happens at runtime when the following code is executed?

def identity(x: int) -> int:
    return x

result = identity("hello")
  1. A.It raises a SyntaxError
  2. B.It automatically casts "hello" to an integer
  3. C.It executes successfully and returns "hello"
  4. D.It raises a TypeError at runtime
Show answer

C. It executes successfully and returns "hello"

Python type hints are purely advisory for static type checkers (like mypy or IDEs) and documentation; standard Python execution does not enforce them at runtime. Therefore, passing a string to a function annotated for integers executes successfully. A common trap is expecting a TypeError at runtime.

Question 3 · decorators · junior

Which of the following is a limitation of this simple memoize decorator?

def memoize(func):
    cache = {}
    def wrapper(*args):
        if args not in cache:
            cache[args] = func(*args)
        return cache[args]
    return wrapper
  1. A.It only works with keyword arguments
  2. B.It fails if arguments include mutable unhashable types like lists
  3. C.It modifies the global scope permanently
  4. D.It caches functions asynchronously
Show answer

B. It fails if arguments include mutable unhashable types like lists

This is a basic memoization decorator that stores function results in a dictionary cache based on arguments. A common trap is that using *args as a dictionary key fails if any argument is a mutable object (like a list) because lists are unhashable.

Ready to apply? Browse remote Python jobs →