Python Full Tutorial — Part 10

Big programs are not written in one file. They are organized into modules and packages.

This is where Python starts feeling like real software engineering.

1. What is a Module?

A module is simply a Python file (.py) containing code.

Example: math_module.py

def add(a, b):
    return a + b

def subtract(a, b):
    return a - b
  

2. Importing a Module

Import Module

import math_module

print(math_module.add(5, 3))
print(math_module.subtract(10, 4))
  

3. Import with Alias

Alias Import

import math_module as mm

print(mm.add(2, 3))
  

4. Import Specific Functions

Selective Import

from math_module import add

print(add(7, 5))
  

5. Built-in Modules

Python comes with many built-in modules.

Using Built-in Modules

import math
import datetime

print(math.sqrt(16))
print(datetime.datetime.now())
  

6. What is a Package?

A package is a folder that contains multiple modules.

Folder Structure

project/
│
├── utils/
│   ├── __init__.py
│   ├── math_utils.py
│   └── string_utils.py
│
└── main.py
  

7. Package Example

math_utils.py

def multiply(a, b):
    return a * b
  
main.py

from utils.math_utils import multiply

print(multiply(4, 5))
  

8. __init__.py Explained

__init__.py tells Python that the folder is a package.

__init__.py

from .math_utils import multiply
  

9. Why Project Structure Matters

10. Real-World Thinking

Beginners write scripts. Engineers design systems.

Modules and packages are the foundation of real Python projects.

Key Takeaway

If your project is more than one file, you need modules. If it grows further, you need packages.

Next part: File Handling (Read / Write / Manage Files).

Disclaimer:
This tutorial is for educational purposes only. Use proper project structures in production environments.