What is a Python package?

Questions & AnswersCategory: PythonWhat is a Python package?
Geek Boy Staff asked 2 years ago

What is a Python package?

a. A package is a collection of one or more modules. Packages are a way to organize your code and allow a hierarchical namespace structure using dot notation. Creating a package is quite simple as it uses the hierarchical file structure of the operating system.

b. A package is another name for a function.

c. A package is a file containing Python code (classes, functions, variables, etc.). The package name is the name of the file without the .py extension. In the package, the package name (as a string) is available as the global variable __name__.

1 Answers
Lokesh Kumar Staff answered 2 years ago

a. A package is a collection of one or more modules. Packages are a way to organize your code and allow a hierarchical namespace structure using dot notation. Creating a package is quite simple as it uses the hierarchical file structure of the operating system.
Explanation

Packages are a way of structuring Python’s module namespace by using “dotted module names”. For example, the module name A.B designates a submodule named B in a package named A. Just like the use of modules saves the authors of different modules from having to worry about each other’s global variable names, the use of dotted module names saves the authors of multi-module packages like NumPy or Pillow from having to worry about each other’s module names.