Interview Q&A / Python

BeginnerQuick answer1 min readUpdated 3 Oct 2026

What is the difference between a module and a package in Python?

SHORT ANSWER

A module is a single .py file. A package is a directory of modules, normally with an __init__.py file, that you import using dotted names like shop.billing. Packages let you organise a large project into a hierarchy.

Explain it simply

A module is one notebook. A package is a bag that holds several related notebooks, say one bag for Maths with notebooks on algebra and geometry. The bag has a label, __init__.py, which runs when the bag is first opened and tells Python "this folder is importable".

Example

text
shop/
    __init__.py
    billing.py
    inventory.py
python
# using the package
import shop.billing
from shop import inventory
from shop.billing import total_price

print(total_price([100, 250]))   # 350

Python also supports namespace packages, folders without __init__.py (Python 3.3+). They work for imports, but a regular package with __init__.py is still the clear and common choice, and it gives you a place to put setup code or to expose a neat public API.

What to say in the interview

"A module is a single Python file; a package is a directory of modules, usually with an __init__.py that marks it as a package and can run initialisation or re-export names. Both are imported with import statements, and packages are how larger code bases are structured."

Common mistakes

  • Naming your own file random.py or json.py, which shadows the standard library module.

#python#modules#packages

Related questions

Practise more Python questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open Python quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.