In this post we’ll be learning about What is init in python and what does it mean. In Python file names are quite different from other programming languages, often confuse developers and hard to understand.

Don’t worry we have all the answere for your question regarding python’s init.py file. So without wasting less time lets get started.

Table of Contents

Getting to know init.py file

The directory in which init.py file is located tells Python to marked that directory as Package. It may be empty or may contain some python code that could be used by package.

A Package is a collection of modules under a single directory. Each module may contain variables, functions and classes. A Package can also have a Sub-Package. We can create Sub-Package simply by creating init.py file inside package directory.

Every time the module inside package is called init.py file is excuted internally.

Below is a example of directory structure.

project
    |
    |
    - package_a ## This is a main package
    |    |
    |    |
    |    - __init__.py
    |    - modules.py
    |    |
    |    - sub_package_1 ## This is a sub package
    |    |    |
    |    |    |
    |    |    - __init__.py
    |    |    - sub_demo1.py
    |
    |
    - student.py ## this file is outside package

#python #learn python

What is __init__ in python and what does it mean?
1.10 GEEK