Module and package are two different things used in Python Programming language. Both of these parameters shall be distinguished before performing actions.
Module and package: Modules
A module is a single Python file that can be imported. Using a module looks like this:
in an interpreter
from module import hi
Module and package: Packages
A package is made up of multiple Python files (or modules), and can even include libraries written in C or C++.
Instead of being a single file, it is an entire folder structure which might look like this:
from package.dog import woof
from package.hi import hi
def hi(): print("Hello world!")
All Python packages must contain an init.py file. When you import a package in your script (import package), the init.py script will be run, giving you access to the all of the functions in the package. In this case, it allows you to use the package.hi and package.woof functions.
Must Read Python Interview Questions
200+ Python Tutorials With Coding Examples
Other Python Tutorials
- What is Python?
- Python Advantages
- Python For Beginners
- Python For Machine Learning
- Machine Learning For Beginners
- 130+ Python Projects With Source Code On GitHub