Modules and Packages in Python

Modules and Packages are the most important and widely used concept in python.Modules and Packages support reusability and easy coding for programmers.

What is a Modules in Python

A Modules is simply a single python file with extension .py. Modules contains global variables and group of functions .Modules is a single executable .py files.we can use functions and global variables in module in any python page by simply importing that module in that page.Here is the example usage of a Modules

Module calculator.py

def sum(a,b):
    sum = a + b 
    print("The sum is: ", sum)


Importing and calling that Module

import calculator

calculator.sum(3,4)

Modules and Packages in Python

What is a Packages in Python

Packages is a collections of modules, it simple a directory that contains lots of modules and a __init__.py file.The package may contains sub package .

employee(Package)
| __init__.py (Constructor)
| contact.py (Module)
| department.py (Module)
| salary.py (Module)

My Thought

Your email address will not be published. Required fields are marked *

Our Tool : hike percentage calculator