Skip to content
BENIBIX Learn

Module (Programming)

Development🧩 Programming ConceptsPrograms

Also known as Module, Code Module, Software Module

A file of code. Other files can import it and use its parts.

Think of it like

It is like a kitchen drawer. Spoons go in one, and pans go in another.

Example

Jack's shop app has a module named prices.py. The cart code imports it to work out each total.

Why it matters

With modules, many people can work on one codebase at once. A bug is easier to find in a small file.

Definition

A module is one file of code that holds parts that go together, like functions and values. Other code can import it and use what is in it. Splitting a program into modules keeps each part small and easy to find. In Python, each .py file is a module. In JavaScript, a file that exports things is one too.

Example code

python
# prices.py
def add_tax(amount):
    return amount * 1.2

# cart.py
from prices import add_tax
print(add_tax(10))  # 12.0
One file holds the tax rule. The other file imports it.
The middle box is a module. It is one file inside the codebase.

Common mistake

Putting all the code in one huge file. It works at first, then nobody can find a thing.

Key takeaways

  1. 1
    Group related code. One job or topic per module.
  2. 2
    Import to use. Other files pull in what they need.
  3. 3
    Small parts. Easier to read, test and change.

Learn it properly