__init.py__

What is __init__.py?

__init__.py is a special file that tells Python:

“This folder is a package — it can be imported.”

Without it (in older Python versions), Python would not treat a directory as importable.

Project Layout

mathlib_project/
├── main.py
└── mathlib/
    ├── __init__.py
    ├── calculator.py
    └── geometry.py

📄 mathlib/calculator.py

class Calculator:
    def add(self, a, b):
        return a + b

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

📄 mathlib/geometry.py


📄 mathlib/__init__.py

Now you can just do from mathlib import Calculator instead of from mathlib.calculator import Calculator.


📄 main.py


▶ How to Run

Make sure you're in the mathlib_project/ directory, then run:

✅ Output

Last updated