Imports are used to import modules, packages, and symbols (functions, Variables, etc) from modules and packages.
To import a module, use the import keyword followed by the module name:
import moduleYou can also give it an alias to avoid name conflicts. To do that use the as keyword:
import module as aliasYou can also selectively import symbols from a module using the from keyword:
from module import symbol1, symbol2Note 1: You can also use the
askeyword here to give the symbols an alias.
from module import symbol1 as alias1, symbol2 as alias2Note 2: You can also use the
*symbol to import all symbols from a module.
from module import *This is not recommended, because it can lead to name conflicts and confusion. Also, the
__all__variable stored in the module is used to define what symbols are imported whenfrom module import *is used, so if it is not defined, no symbols will be imported even if the module contains symbols.