ME2 SWE EXAM QUESTIONS ALREADY ANSWERED | TOP
RATED | 2026/2027 VERSION
1. Q: What is the Global Interpreter Lock (GIL) in Python? ANSWER A
mutex that protects access to Python objects, preventing multiple
native threads from executing Python bytecodes simultaneously.
2. Q: How does the GIL affect ML workloads? ANSWER It bottlenecks
CPU-bound multi-threading in pure Python, which is why
NumPy/Pandas release it during C-level computations, and
multiprocessing is preferred for pure Python parallelism.
3. Q: What is the difference between a list and a generator in Python?
ANSWER A list stores all elements in memory; a generator produces
elements lazily one at a time, saving memory.
4. Q: When would you use a generator in an ML data pipeline?
ANSWER When loading datasets too large to fit into RAM (e.g.,
streaming image or text data from disk during training).
5. Q: Explain *args and **kwargs. ANSWER *args allows passing a
variable number of non-keyword arguments; **kwargs allows
passing a variable number of keyword arguments.
6. Q: What is a Python decorator? ANSWER A function that takes
another function and extends its behavior without explicitly
modifying it (e.g., @timer, @lru_cache).
7. Q: How do you manage dependencies in a Python ML project?
ANSWER Using environment managers like conda, venv, and
locking dependency versions via requirements.txt, Pipfile, or
Poetry.
8. Q: What is the difference between == and is in Python? ANSWER
== checks for value equality; is checks for object identity (whether
two variables point to the same memory location).
,9. Q: What are context managers? ANSWER Constructs (using the
with statement) that allocate and release resources precisely, such
as opening/closing files or database connections.
10. Q: How does __init__ differ from __new__? ANSWER __new__ is
responsible for creating and returning a new instance, while __init__
initializes the state of that instance.
11. Q: What is monkey patching? ANSWER Dynamically
modifying a class or module at runtime (sometimes used in testing
to mock heavy ML models).
12. Q: Explain the SOLID principle of "Dependency Inversion".
ANSWER High-level modules should not depend on low-level
modules; both should depend on abstractions (interfaces).
13. Q: How would you implement Dependency Injection in
Python? ANSWER By passing required objects (like a database
connector or model instance) into a class's __init__ method rather
than instantiating them inside the class.
14. Q: What is a thread pool? ANSWER A collection of pre-
instantiated worker threads that wait for tasks to be assigned,
avoiding the overhead of creating/destroying threads for short
tasks.
15. Q: When would you use multiprocessing vs multithreading
in Python? ANSWER Multiprocessing for CPU-bound tasks (e.g.,
data preprocessing); Multithreading for I/O-bound tasks (e.g.,
fetching data from APIs).
16. Q: What does the yield keyword do? ANSWER It turns a
function into a generator, pausing its state and yielding a value
without destroying the local variables.
17. Q: What is method resolution order (MRO) in Python?
ANSWER The order in which Python looks for a method in a
hierarchy of classes, primarily used in multiple inheritance (follows
C3 linearization).
18. Q: How do you handle exceptions in a data pipeline without
crashing the whole run? ANSWER Wrap individual data processing
logic in try/except blocks, log the error, and optionally skip the bad
record or send it to a dead-letter queue.
,19. Q: What is a static method vs a class method? ANSWER A
static method (@staticmethod) doesn't take self or cls. A class
method (@classmethod) takes cls as the first argument and can
modify class state.
20. Q: Why use type hinting in ML codebases? ANSWER It
improves code readability, helps catch bugs early via static analysis
tools (like mypy), and is essential for team collaboration.
21. Q: What is Git rebase? ANSWER Moving a sequence of
commits to a new base commit, creating a linear project history,
unlike merge which creates a merge commit.
22. Q: What is a detached HEAD state in Git? ANSWER You are
viewing a specific commit, not a branch, meaning any new commits
won't belong to a branch and may be lost if not tracked.
23. Q: Explain the concept of "favor composition over
inheritance." ANSWER Instead of creating deep class hierarchies
(inheritance), build complex objects by combining smaller, distinct,
reusable objects (composition).
24. Q: What is a factory pattern? ANSWER A creational design
pattern that provides an interface for creating objects in a
superclass, but allows subclasses to alter the type of objects that
will be created (e.g., a ModelFactory).
25. Q: How do you write unit tests for a function that queries a
database? ANSWER Use mocking (e.g., unittest.mock.patch) to
replace the database call with a fake object that returns
predetermined data.
26. Q: What is test-driven development (TDD)? ANSWER Writing
the automated unit tests before writing the actual production code.
27. Q: What is code coverage? ANSWER A metric measuring the
percentage of source code executed by tests.
28. Q: Why is 100% code coverage not always good? ANSWER It
can create a false sense of security if the tests don't assert the
correct logic, and it encourages writing useless tests just to hit
metrics.
, 29. Q: What is a linter and formatter? ANSWER A linter (e.g.,
flake8, pylint) catches logical/syntax errors; a formatter (e.g.,
black) enforces consistent code styling.
30. Q: What are magic methods (dunder methods) in Python?
ANSWER Special methods surrounded by double underscores (e.g.,
__len__, __repr__, __call__) that allow classes to integrate with
Python's built-in operations.
31. Q: How does __call__ work? ANSWER It allows an instance of
a class to be called as a function (standard pattern for custom
PyTorch/Keras model classes).
32. Q: What is a shallow copy vs a deep copy? ANSWER Shallow
copy creates a new object but inserts references to the original
nested objects; deep copy recursively copies all nested objects.
33. Q: What is the dataclass decorator used for? ANSWER To
automatically generate __init__, __repr__, and __eq__ methods for
classes that primarily store state.
34. Q: What is continuous integration (CI)? ANSWER The practice
of automatically merging and testing code changes to a shared
repository multiple times a day.
35. Q: What is continuous deployment (CD)? ANSWER
Automatically releasing validated code changes to production.
36. Q: Name a common CI/CD tool used in ML. ANSWER GitHub
Actions, GitLab CI, or Jenkins.
37. Q: What is a Dockerfile? ANSWER A text document containing
all the commands to assemble a Docker image (e.g., base Python
image, install dependencies, copy code).
38. Q: What is the difference between a Docker image and a
container? ANSWER An image is a read-only template with
instructions; a container is a runnable instance of an image.
39. Q: Why use Docker for ML models? ANSWER It ensures
environment parity (same libraries/versions) across local dev,
staging, and production, eliminating "it works on my machine"
issues.
RATED | 2026/2027 VERSION
1. Q: What is the Global Interpreter Lock (GIL) in Python? ANSWER A
mutex that protects access to Python objects, preventing multiple
native threads from executing Python bytecodes simultaneously.
2. Q: How does the GIL affect ML workloads? ANSWER It bottlenecks
CPU-bound multi-threading in pure Python, which is why
NumPy/Pandas release it during C-level computations, and
multiprocessing is preferred for pure Python parallelism.
3. Q: What is the difference between a list and a generator in Python?
ANSWER A list stores all elements in memory; a generator produces
elements lazily one at a time, saving memory.
4. Q: When would you use a generator in an ML data pipeline?
ANSWER When loading datasets too large to fit into RAM (e.g.,
streaming image or text data from disk during training).
5. Q: Explain *args and **kwargs. ANSWER *args allows passing a
variable number of non-keyword arguments; **kwargs allows
passing a variable number of keyword arguments.
6. Q: What is a Python decorator? ANSWER A function that takes
another function and extends its behavior without explicitly
modifying it (e.g., @timer, @lru_cache).
7. Q: How do you manage dependencies in a Python ML project?
ANSWER Using environment managers like conda, venv, and
locking dependency versions via requirements.txt, Pipfile, or
Poetry.
8. Q: What is the difference between == and is in Python? ANSWER
== checks for value equality; is checks for object identity (whether
two variables point to the same memory location).
,9. Q: What are context managers? ANSWER Constructs (using the
with statement) that allocate and release resources precisely, such
as opening/closing files or database connections.
10. Q: How does __init__ differ from __new__? ANSWER __new__ is
responsible for creating and returning a new instance, while __init__
initializes the state of that instance.
11. Q: What is monkey patching? ANSWER Dynamically
modifying a class or module at runtime (sometimes used in testing
to mock heavy ML models).
12. Q: Explain the SOLID principle of "Dependency Inversion".
ANSWER High-level modules should not depend on low-level
modules; both should depend on abstractions (interfaces).
13. Q: How would you implement Dependency Injection in
Python? ANSWER By passing required objects (like a database
connector or model instance) into a class's __init__ method rather
than instantiating them inside the class.
14. Q: What is a thread pool? ANSWER A collection of pre-
instantiated worker threads that wait for tasks to be assigned,
avoiding the overhead of creating/destroying threads for short
tasks.
15. Q: When would you use multiprocessing vs multithreading
in Python? ANSWER Multiprocessing for CPU-bound tasks (e.g.,
data preprocessing); Multithreading for I/O-bound tasks (e.g.,
fetching data from APIs).
16. Q: What does the yield keyword do? ANSWER It turns a
function into a generator, pausing its state and yielding a value
without destroying the local variables.
17. Q: What is method resolution order (MRO) in Python?
ANSWER The order in which Python looks for a method in a
hierarchy of classes, primarily used in multiple inheritance (follows
C3 linearization).
18. Q: How do you handle exceptions in a data pipeline without
crashing the whole run? ANSWER Wrap individual data processing
logic in try/except blocks, log the error, and optionally skip the bad
record or send it to a dead-letter queue.
,19. Q: What is a static method vs a class method? ANSWER A
static method (@staticmethod) doesn't take self or cls. A class
method (@classmethod) takes cls as the first argument and can
modify class state.
20. Q: Why use type hinting in ML codebases? ANSWER It
improves code readability, helps catch bugs early via static analysis
tools (like mypy), and is essential for team collaboration.
21. Q: What is Git rebase? ANSWER Moving a sequence of
commits to a new base commit, creating a linear project history,
unlike merge which creates a merge commit.
22. Q: What is a detached HEAD state in Git? ANSWER You are
viewing a specific commit, not a branch, meaning any new commits
won't belong to a branch and may be lost if not tracked.
23. Q: Explain the concept of "favor composition over
inheritance." ANSWER Instead of creating deep class hierarchies
(inheritance), build complex objects by combining smaller, distinct,
reusable objects (composition).
24. Q: What is a factory pattern? ANSWER A creational design
pattern that provides an interface for creating objects in a
superclass, but allows subclasses to alter the type of objects that
will be created (e.g., a ModelFactory).
25. Q: How do you write unit tests for a function that queries a
database? ANSWER Use mocking (e.g., unittest.mock.patch) to
replace the database call with a fake object that returns
predetermined data.
26. Q: What is test-driven development (TDD)? ANSWER Writing
the automated unit tests before writing the actual production code.
27. Q: What is code coverage? ANSWER A metric measuring the
percentage of source code executed by tests.
28. Q: Why is 100% code coverage not always good? ANSWER It
can create a false sense of security if the tests don't assert the
correct logic, and it encourages writing useless tests just to hit
metrics.
, 29. Q: What is a linter and formatter? ANSWER A linter (e.g.,
flake8, pylint) catches logical/syntax errors; a formatter (e.g.,
black) enforces consistent code styling.
30. Q: What are magic methods (dunder methods) in Python?
ANSWER Special methods surrounded by double underscores (e.g.,
__len__, __repr__, __call__) that allow classes to integrate with
Python's built-in operations.
31. Q: How does __call__ work? ANSWER It allows an instance of
a class to be called as a function (standard pattern for custom
PyTorch/Keras model classes).
32. Q: What is a shallow copy vs a deep copy? ANSWER Shallow
copy creates a new object but inserts references to the original
nested objects; deep copy recursively copies all nested objects.
33. Q: What is the dataclass decorator used for? ANSWER To
automatically generate __init__, __repr__, and __eq__ methods for
classes that primarily store state.
34. Q: What is continuous integration (CI)? ANSWER The practice
of automatically merging and testing code changes to a shared
repository multiple times a day.
35. Q: What is continuous deployment (CD)? ANSWER
Automatically releasing validated code changes to production.
36. Q: Name a common CI/CD tool used in ML. ANSWER GitHub
Actions, GitLab CI, or Jenkins.
37. Q: What is a Dockerfile? ANSWER A text document containing
all the commands to assemble a Docker image (e.g., base Python
image, install dependencies, copy code).
38. Q: What is the difference between a Docker image and a
container? ANSWER An image is a read-only template with
instructions; a container is a runnable instance of an image.
39. Q: Why use Docker for ML models? ANSWER It ensures
environment parity (same libraries/versions) across local dev,
staging, and production, eliminating "it works on my machine"
issues.