Import Statements in Python
Import Statements in Python
By writing an import statement, we can import a module (a file that contains Python definitions and statements) into another file. These are various alternatives for import statements: First Alternative:
For example:
If we use this import statement, we will need to add the name of the module before the name of the function or element that we are referring to in our code:
We explicitly mention in our code the module that the element belongs to. Second Alternative:
For example:
In our code, we can use the new name that we assigned instead of the original name of the module:
Third Alternative:
For example:
With this import statement, we can call the function directly without specifiying the name of the module:
Fourth Alternative:
For example:
With this import statement, we can assign a new name to the element imported from the module:
Fifth Alternative:
This statement imports all the elements of the module and you can refer to them directly by their name without specifying the name of the module. For example:
According to the Style Guide for Python Code: Wildcard imports (from
S.Schins BASICS
Python Basics Examples