Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Modules and Packages | Python Fundamentals lesson | BraveProgrammer
  1. Courses
  2. /
  3. Python Fundamentals

Lesson 21 of 55

·Python

Modules and Packages

20 minutes

Course progress38%

What you'll learn

Keep these ideas in mind as you work through the lesson.

4 points
  • Modules are individual `.py` files; import them with `import module_name`.
  • Packages are directories with an `__init__.py` that can contain sub‑modules.
  • Use relative imports (`from . import helper`) inside packages.
  • Keep related functionality together for readability and reuse.

Modules and Packages

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.

Make it stickPractice what you've learned1 quiz · 5 practical tests · Optional activities from Python FundamentalsBrowse activities
Previous lessonException HandlingContinue to lesson 22Importing Standard LibraryBack to Python Fundamentals curriculum