Modules in Python

ImportsPackages

Modules are files containing Python code (functions, classes, variables) that you can import into other files. They help organize code, avoid repetition, and make programs easier to maintain.

Python comes with a rich standard library of modules, and you can create your own.

Importing Modules

Use import to load a module.

Import Specific Names

Use from ... import to import specific items.

Aliases with as

Creating Your Own Module

Save functions in a .py file and import it.

__name__ == "__main__" Guard

Run code only when file is executed directly, not when imported.

Quick Quiz

We have reviewed and checked the materials, but errors may still occur. The content is provided for educational purposes only, so use it at your own responsibility and verify with other sources if needed.

✨ Ask Lara — your AI study partner

Unlock personalized learning support. Lara can explain lessons, summarize topics, and answer your study questions — available from the Go plan and above.


Lara helps you learn faster — exclusive to ReadyTools Go, Plus, and Max members.

Track Your Progress 🚀

Learn more easily by tracking your progress completely for free.