- 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
[pastacode lang=”python” manual=”%23%20importing%20the%20library%20and%20module%20%20%0Aimport%20math%20%20%0Afrom%20math%20import%20pow%20%20%0A%23%20using%20the%20pow()%20function%20%20%0Apow(3%2C%205)%20%20%0A%23%20printing%20pow()%20%20%0Aprint(pow)%20%20%0A%0A” message=”” highlight=”” provider=”manual”/]
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
[pastacode lang=”python” manual=”%23%20importing%20the%20package%20%20%0Aimport%20math%20%20%0A%23%20printing%20a%20statement%20%20%0Aprint(%22We%20have%20imported%20the%20math%20package%22)%20%20%0A%0A” message=”” highlight=”” provider=”manual”/]
Output
