Skip to content
Python Programming

Python Modules and Packages

Beginner Lesson 7 of 10

Learn how to organize code into reusable modules and packages.

mymodule.py
def greet(name):
return f"Hello, {name}!"
PI = 3.14159
import mymodule
print(mymodule.greet("Alice"))
from mymodule import greet, PI
print(greet("Bob"))
from mymodule import * # Import all
import mymodule as mm # Alias
import os
import sys
import datetime
import json
import random
import math
mypackage/
__init__.py
module1.py
module2.py
subpackage/
__init__.py
module3.py

Continue to File Handling →