Interview Q&A · questions with model answers
Python Developer Interview Questions
Part of the study plan for: Full Stack Engineer · Native AI Engineer · Forward Deployed Engineer (FDE) · Machine Learning Engineer · Data Engineer
Ordered by how often they're asked. Most-asked answers are free to read in full; members see every answer and can rate their confidence on each.
-
Most asked Explain mutable vs immutable in Python.
Mutable objects can change in place after creation; immutable objects cannot change their value once created.
-
Most asked Explain is vs == in Python.
== checks value equality, while is checks whether two variables reference the exact same object.
-
Most asked Explain threading vs multiprocessing vs asyncio in Python.
Use threading for blocking I/O concurrency, multiprocessing for CPU parallelism, and asyncio for high-concurrency non-blocking I/O.
-
Most asked Backend Python interview: explain authN vs authZ.
Authentication proves who the user or service is; authorization decides what that identity is allowed to do.
-
Most asked Explain deepcopy vs copy in Python.
copy.copy creates a shallow copy, while copy.deepcopy recursively copies nested objects.
-
When do you use the `asyncio` module/package?
Use asyncio for high-concurrency I/O where tasks spend much of their time waiting on sockets, timers, subprocesses, or other async operations.
-
When do you use the `logging` module/package?
Use logging for structured, leveled, configurable application events instead of print statements.
-
When do you use the `unittest / pytest` module/package?
Use unittest or pytest to automate tests; pytest is often preferred for concise tests, fixtures, parametrization, and plugin support.
-
When do you use the `venv` module/package?
Use venv to create isolated Python environments per project so dependencies do not conflict globally.
-
Which pytest features do you use most?
Fixtures (with scopes and yield teardown, shared via conftest.py), @pytest.mark.parametrize for table-driven tests, monkeypatch and unittest.mock for doubles, tmp_path for files, markers for…
-
When do you use the `pathlib` module/package?
Use pathlib for object-oriented, cross-platform filesystem path handling.
-
When do you use the `collections` module/package?
Use collections for specialized container types beyond built-in list, dict, tuple, and set.
-
When do you use the `itertools` module/package?
Use itertools for memory-efficient iterator building blocks such as chaining, grouping, slicing, combinations, and infinite sequences.
-
When do you use the `functools` module/package?
Use functools for higher-order function utilities such as caching, wrapping, partial application, ordering helpers, and singledispatch.
-
When do you use the `json` module/package?
Use json to serialize and deserialize JSON for APIs, config, logs, fixtures, and interoperable data exchange.
-
When do you use the `concurrent.futures` module/package?
Use concurrent.futures for a high-level thread or process pool API built around Executor and Future.
-
When do you use the `secrets` module/package?
Use secrets for cryptographically secure random tokens, codes, and secret values.
-
Python packaging: requirements.txt vs pyproject.toml?
requirements.txt is commonly used to install pinned dependencies, while pyproject.toml defines project metadata, build system, and modern tool configuration.
-
Backend Python interview: explain Django ORM vs SQLAlchemy.
Django ORM is integrated into Django's batteries-included framework, while SQLAlchemy is a standalone, highly flexible ORM and SQL toolkit.
-
When do you use `TypedDict`, `Literal`, `Protocol` and `@overload`?
TypedDict types dict-shaped data like JSON payloads; Literal restricts values to specific constants; Protocol describes structural interfaces (static duck typing); @overload declares multiple…
-
Compare dataclasses, attrs and Pydantic models.
dataclasses (stdlib) generate boilerplate (init, repr, eq) without validation; attrs offers similar features with more options (validators, converters, slots by default); Pydantic validates and…
-
Explain the iterator protocol and the difference between iterables and iterators.
An iterable implements iter() returning an iterator; an iterator implements next() (raising StopIteration when exhausted) and iter() returning itself. Lists are iterables (re-iterable); iterators…
-
What's the difference between `__new__` and `__init__`?
new is a static method that creates and returns a new instance (it receives the class); init initializes an already-created instance (it receives self) and must return None.
-
What's the difference between `str` and `bytes`, and how do you handle encodings?
str is Unicode text (code points); bytes is raw binary data. Convert with .encode('utf-8') and .decode('utf-8') at I/O boundaries, and specify encoding='utf-8' when opening text files.
-
Why is `pickle` dangerous, and what should you use instead?
Unpickling data can execute arbitrary code, since objects can define reduce to call any function, so never unpickle untrusted data. Use JSON, MessagePack or Protobuf for data exchange, and sign…
-
What is the difference between WSGI and ASGI, and how does it affect how a Python web app handles concurrent requests?
WSGI is synchronous: each request occupies a worker process or thread until it finishes, so concurrency equals the number of workers and threads. ASGI is asynchronous: many requests run as…
-
When do you use the `argparse` module/package?
Use argparse to build command-line interfaces with typed arguments, flags, help text, defaults, and validation.
-
When do you use the `dataclasses.asdict` module/package?
Use dataclasses.asdict to convert a dataclass instance into nested dictionaries, but be aware that it recursively copies dataclass fields.
-
When do you use the `enum` module/package?
Use enum to define a fixed set of named constants with type identity and readable names.
-
When do you use the `hashlib` module/package?
Use hashlib for cryptographic hash functions such as SHA-256 to create deterministic digests of bytes.
-
Python packaging: wheels vs sdist?
A wheel is a built distribution ready to install, while an sdist is a source distribution that must be built during installation.
-
Why can floating-point math surprise you, and when should you use `Decimal` or `Fraction`?
Floats are binary approximations, so 0.1 + 0.2 != 0.3. Use decimal.Decimal (constructed from strings) for money and exact decimal arithmetic with controlled rounding, fractions.Fraction for exact…
-
Which `contextlib` utilities are worth knowing?
@contextmanager and @asynccontextmanager (build context managers from generators), ExitStack (manage a dynamic number of contexts), suppress (ignore specific exceptions), closing, redirect_stdout,…
-
Compare f-strings, `str.format` and `%` formatting.
f-strings (3.6+) are the most readable and fastest for inline formatting, supporting expressions and format specs ({price:.2f}, {value!r}, {x=} for debugging). str.format suits templates defined…
-
Which built-ins make Python loops cleaner?
enumerate (index + value), zip (parallel iteration; strict=True in 3.10+ raises on length mismatch), reversed, sorted with key, any/all, sum/min/max with key and default, map/filter, and…
-
How do Django, Flask and FastAPI compare for a new backend project?
Django is batteries-included (ORM, admin, auth, migrations), great for full-featured products; Flask is minimal and flexible, ideal for small services or custom stacks; FastAPI is typed, async-first…
-
What is the difference between a list and a tuple in Python?
Lists are mutable and can be modified after creation; tuples are immutable and have fixed length.