Python Modules, Libraries, and Packages
What are Python Libraries vs Modules?
Library
A collection of modules. Libraries are typically organized to group related functionality together (modules).
Modules
A module is a single file that contains Python a collection of functions, typically organized around a specific functionality or set of related functionalities.
How to import modules?
There are two import methods: General and Selective.
1. General Import
We can import python modules by using the import statement:
import <module_name>
To call a function from a module, we use the following dot notation syntax:
<module_name>.<function>
3. Selective Import
You can choose to import only parts from a module, by using the from keyword:
from <module_name> import <element_of_module>
Dot notation is not required to call the function.
This means that when importing using the from keyword, do not use the module name when referring to elements in the module.
Renaming a module
You can create an alias when you import a module, by using the as keyword:
import <module_name> as <alias>