Module
noun
say it: “MOJ-ool” /ˈmɒdʒuːl/
A Python file whose functions and values other files can use by importing it; Python comes with many, and every .py file you write is one too.
What is a module in Python?
A module is a Python file whose code you can use in another file. Python comes with many, and any .py file you write is a module too.
# helpers.py
def format_price(amount):
return f"${amount:.2f}"
# shop.py
import helpers
print(helpers.format_price(4.5)) # $4.50
In a sentence
- “She moved the price helpers into their own module and imported it from shop.py.”
- “The random module comes with Python, so there's nothing to install.”
Level: Apprentice · More Python terms at this level
Updated