• It is often that programmers and many coders may confuse between a module and a package.
  • Generally, arises when it becomes hard to identify when and where a package or module should be implemented.
  • In python programming language module and packages will make it easy for the programmers to work more professionally while dealing with both modules and packages.

Modules

  • A module is a pythonic statement that containing different functions.
  • Modules are act as a pre-defined library in the script, which is accessible to both the programmers as well as the user.
  • These modules are also store pre-defined functions from the library where the code is being executed.

Sample Code

# importing the library and module  
import math
from math import pow
# using the pow() function
pow(3, 5)
# printing pow()
print(pow)

Output

Packages

  • A package is considered as a collection of tools that allows the programmers to initiate the code.
  • Python package acts as a user-variable interface to any source code.
  • At runtime this feature allows a Python package to work at a defined time for any functional script.

Sample Code

# importing the package  
import math
# printing a statement
print("We have imported the math package")

Output

Categorized in: