InterviewSolution
| 1. |
What are modules and packages in Python? |
|
Answer» Python packages and Python modules are two mechanisms that allow for MODULAR programming in Python. Modularizing has several advantages -
Modules, in general, are simply Python files with a .py EXTENSION and can have a set of functions, classes, or variables defined and implemented. They can be imported and initialized once using the import statement. If partial functionality is needed, import the requisite classes or functions using from foo import bar. Packages allow for hierarchial structuring of the module namespace using dot notation. As, modules help avoid clashes between global variable names, in a similar manner, packages help avoid clashes between module names. Note: You can technically import the package as well, but alas, it doesn't import the modules within the package to the local namespace, thus, it is practically useless. |
|