Lesson 21 of 55
PythonModules and Packages
20 minutes
Course progress38%
What you'll learn
Keep these ideas in mind as you work through the lesson.
Lesson 21 of 55
Python20 minutes
Keep these ideas in mind as you work through the lesson.
A module is a single .py file that can be imported. A package is a directory containing an __init__.py file, allowing you to group related modules together.
# my_module.py
def hello(name):
return f'Hello, {name}!'
# In another script
import my_module
print(my_module.hello('Bob'))
Organizing code into modules and packages makes large projects easier to maintain and reuse.