← Python

Creating Modules (.py files to import)

A .py file becomes a module that other scripts can import to reuse its functions

What it does: After import helpers, access its functions with helpers.function_name(). 'from module import name' lets you use the name directly without the module prefix. Any .py file is a module — import it to use what's inside. Modules let you split code into files and share functions across projects. Python searches the current folder and sys.path — same folder always works. * imports all public names — generally avoided as it pollutes the namespace. A module is just a Python file — it can hold anything at the top level. Module (file) names cannot contain spaces. Use underscores: my_module.py.

Common mistakes: Don't include .py: just the module name. Module names are case-sensitive. File is helpers.py, so use helpers.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a journey and assign it to your class.

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
What is a module?
A .py file with functions you can importA folder
Matches
❌ import my module
Error: Module names can't have spaces
Applying
Meanings
Term
Module
Meaning
Any .py file that can be imported and reused.
Practice
def greet(name):
Testing
Gaps
helpers
Check Answer
Spots
1# Import our helpers module
2import helpers.py

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Armadillo' badge — Shield Bearer, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. What is a module?
A. A .py file with functions you can import ✓
B. A folder
Any .py file is a module — import it to use what's inside
2. If you create helpers.py, how do you import it?
A. import helpers.py
B. import helpers ✓
Drop the .py extension — import uses the module name, not the filename
3. from math import sqrt what does this do?
A. Imports only the sqrt function ✓
B. Imports everything
from X import Y imports just Y — use it directly without the module prefix
4. Why create your own modules?
A. Python requires it
B. To organize and reuse code ✓
Modules let you split code into files and share functions across projects
5. Where must your module file be?
A. In the same folder (or Python's path) ✓
B. In a special folder only
Python searches the current folder and sys.path — same folder always works

Match the Pairs

import my module Error: Module names can't have spaces
from helpers import greet() Error: Must name what to import
import helpers helpers.greet() Valid: Use module prefix
from helpers import greet greet() Ok: Import specific function
# In helpers.py: def greet(): print('Hi') Output: (defines greet in module)
# In main.py: import helpers helpers.greet() Output: Hi

Key Term

Module
Any .py file that can be imported and reused.~~import module

Fill in the Blanks

1. import helpers print(helpers.greet('Al'))
2. from helpers import greet print(greet('Al'))
3. import helpers print(helpers.greet('Alice'))
4. if __name__ == '__main__': print('Running directly')
5. from helpers import add result = add(3, 5)

Spot the Error

Question 1
A # Import our helpers module
B import helpers.py
C helpers.greet('Alice')
D print('Done')
Line B — Don't include .py: just the module name
Question 2
A import Helpers
B result = Helpers.greet('Al')
C print(result)
D print('Done')
Line A — Module names are case-sensitive. File is helpers.py, so use helpers.
Question 3
A from helpers import greet
B result = helpers.greet('Al')
C print(result)
D print('Done')
Line B — With 'from import', use greet() directly: no module prefix
Question 4
A import helpers
B result = greet('Al')
C print(result)
D print('Done')
Line B — With 'import helpers', must use helpers.greet() not just greet()
Question 5
A from helpers import *
B # imports everything
C greet('Alice')
D # recommended approach?
Line B — import * is not recommended: import specific functions for clarity
For Teachers

Create a free class, add this module to a journey, and track who's stuck.

Create a free teacher account →

No credit card. No setup fee. Make a class and invite students in under three minutes.

For Students

Practice this topic interactively, track progress, and unlock badges.

Start Learning Free →

Have a class code?