Python · Module 5Module material
Organising Code interview questions
25 questions interviewers ask on this module’s topics, from first principles to the follow-ups. Each comes with a model answer.
Modules and packages
- What is the difference between a module and a package?●
- What happens when Python runs
import text_tools?● - What is the difference between
import math,from math import sqrtandfrom math import *?●● - What does
if __name__ == "__main__":do?●● - Where does Python look for a module, and what can go wrong?●●
- Is
__init__.pyrequired to make a package?●●
Environments
- What is a virtual environment, and why use one per project?●
- What is the difference between
pyproject.tomlanduv.lock?●● - How do
uv add,pip installandpython -m venvrelate?●● - Should
.venvbe committed to version control?●
Files
- Why use
with open(...) as f:?● - What do the modes
"r","w","a"and"x"do?●● - Why should every
openname an encoding?●● - What type are the values
csv.DictReadergives?●● - What changes when a Python object goes through JSON and back?●●
Exceptions
- How do you read a traceback?●
- Why is
except Exception: passa bad idea?●● - What do
elseandfinallydo in atrystatement?●● - When should a function raise an exception, and which type?●●
Debugging, testing and tools
- How do you approach a bug?●
- What does
breakpoint()do?●● - What makes a good test?●●
- How do you test that a function raises an error?●●
- What is the difference between a formatter, a linter and a type checker?●●
- If Ruff and mypy report nothing, is the code correct?●●