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

A module is a single Python file (.py) that has functions, classes or variables. A package is a folder that groups related modules together.

import math
print(math.sqrt(16))

from math import pi
print(pi)

Output:

Tutorials Class - Output Window

4.0
3.141592653589793

A package looks like this on disk:

shop/
    __init__.py
    cart.py
    payment.py
from shop import cart
from shop.payment import pay

The __init__.py file marks the folder as a regular package. Python can also use folders without it, but most projects still keep the file. Python comes with many built-in modules, and you can install more with pip.


Learn more about the similar topics:
Tutorials
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.