what is package in python

10 months ago 29
Nature

In Python, a package is a container that contains various modules to perform specific tasks. A package is a folder that contains various modules as files. Physically, a package is a folder containing modules and maybe other folders that themselves may contain more folders and modules. Conceptually, it’s a namespace. This simply means that a package’s modules are bound together by a package name, by which they may be referenced. A package usually consists of several modules. Python modules may contain several classes, functions, variables, etc., whereas Python packages contain several modules. To create a package, we need to create a folder that contains an empty Python file named init.py and other modules. The init.py file helps the Python interpreter recognize the folder as a package and specifies the resources to be imported from the modules. We can import modules from packages using the dot (.) operator. For example, if we want to import the module named mod1 from the package named pkg, we can use the following statement: import pkg.mod1 .