Home >Backend Development >Python Tutorial >What Does the `import *` Statement Actually Import in Python?
What the Import * Statement Imports
In Python, the import * statement imports all objects from the specified module into the current module. This allows the use of exported symbols (variables, classes, methods, etc.) from the imported module without prefixing them with the module name.
Example:
>>> from math import * >>> pi 3.141592653589793 >>> sin(pi/2) 1.0
Comparison to Explicit Imports:
However, using import * is generally discouraged due to:
Instead, it's better practice to:
Exceptions:
Some libraries may have specialized sub-modules designed to be imported with import *. For instance, the Pygame library's pygame.locals sub-module contains commonly used constants and functions.
Importing from Sub-Modules:
Importing from sub-modules requires explicit specification, even when using import * within the sub-module. For example, from urllib import * does not import all sub-modules like urllib.request.
The above is the detailed content of What Does the `import *` Statement Actually Import in Python?. For more information, please follow other related articles on the PHP Chinese website!