Quiz: Python
Python questions from real interviews as a quiz, with an explanation for every option.
Try it: 5 questions
Loading…
Sample questions
Who is generally credited with formulating the core SOLID principles?
- Grady Booch
- Martin Fowler
- Michael Feathers
- Robert C. Martin
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.
Which SQLAlchemy ORM method is used to join the
UserandAddresstables using a join condition?filter()join()group_by()union()
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
How should a decorator be typed to preserve the original function's parameter and return types?
- Use one
TypeVarfor the entireCallabletype and leave the wrapper unannotated. - Annotate the wrapper as
Callable[[], None]and usewrapsto copy the metadata. - Use
ParamSpecfor the parameters andTypeVarfor the result in theCallabletype. - Use
Callable[..., Any]for both the function and the wrapper.
- Use one
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])
- A list, such as
Which file conventionally indicates that a directory is a regular Python package?
__init__.py__main__.pypackage.pyrequirements.txt
Which patterns does FastAPI use to group routes and manage application dependencies? Choose two.
- Observer: handlers subscribe to changes in application state
- Router:
APIRoutergroups 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
What is
RuntimeErrorin 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.
How is Python's
floattypically represented on platforms where it uses a 64-bitdouble?- 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