NewWork mode: your Claude Code or Codex on work calls, answering from your project's codeSkip to content

Quiz: Python

Python questions from real interviews as a quiz, with an explanation for every option.

25 questionsAll topicsPython

Try it: 5 questions

Loading…

Sample questions

  1. Who is generally credited with formulating the core SOLID principles?

    • Grady Booch
    • Martin Fowler
    • Michael Feathers
    • Robert C. Martin
    Full answer
  2. Which approach is best suited for a zero-downtime database schema migration?

    • Deploy an application that only works with the new schema first, then migrate the data.
    • Stop the service, change the schema and all data, then restart it with the new application version.
    • Remove the old columns and tables first, then deploy the application that uses the new schema.
    • Expand–migrate–contract: make compatible changes, migrate the data, switch the application, and remove the old schema later.
    Full answer
  3. Which SQLAlchemy ORM method is used to join the User and Address tables using a join condition?

    • filter()
    • join()
    • group_by()
    • union()
    Full answer
  4. In a standard GIL-enabled CPython build, how many threads can execute Python bytecode at the same time within one interpreter?

    • As many as there are running threads
    • As many as there are CPU cores
    • Two
    • One
    Full answer
  5. How should a decorator be typed to preserve the original function's parameter and return types?

    • Use one TypeVar for the entire Callable type and leave the wrapper unannotated.
    • Annotate the wrapper as Callable[[], None] and use wraps to copy the metadata.
    • Use ParamSpec for the parameters and TypeVar for the result in the Callable type.
    • Use Callable[..., Any] for both the function and the wrapper.
    Full answer
  6. Which of the following values can be used as keys in a Python dictionary? Select all that apply.

    • A list, such as [1, 2]
    • A tuple containing only hashable values, such as (1, "x")
    • A string, such as "user"
    • An integer, such as 42
    • A tuple containing a list, such as (1, [2])
    Full answer
  7. Which file conventionally indicates that a directory is a regular Python package?

    • __init__.py
    • __main__.py
    • package.py
    • requirements.txt
    Full answer
  8. Which patterns does FastAPI use to group routes and manage application dependencies? Choose two.

    • Observer: handlers subscribe to changes in application state
    • Router: APIRouter groups related routes
    • Dependency Injection: dependencies are provided to handlers through FastAPI’s mechanism
    • Singleton: every handler automatically receives a single service instance
    • Factory Method: each route creates a separate application instance
    Full answer
  9. What is RuntimeError in Python?

    • A warning about a program running slowly or inefficiently.
    • The base class for all exceptions that occur while a program runs.
    • An exception raised only when code has invalid syntax.
    • A built-in exception for runtime errors that do not fit a more specific exception type.
    Full answer
  10. How is Python's float typically represented on platforms where it uses a 64-bit double?

    • A decimal representation with a fixed number of digits after the point
    • IEEE 754 binary32: 1 sign bit, 8 exponent bits, and 23 fraction bits
    • IEEE 754 binary64: 1 sign bit, 11 exponent bits, and 52 fraction bits
    • An integer plus a separate decimal fraction of arbitrary precision
    Full answer