In this article, let’s take a look at the import statement in python. Friends who are new to this language may not understand what the Pythonimport statement means. So this article will introduce you to the import statement and understand the usage of import in python.
Import statement:
After the module module is defined, we can use the import statement to introduce the module. The syntax is as follows:
import module1[, module2[,... moduleN]
form.. .import statement :
Python’s from statement lets you import a specified section from a module into the current namespace. The syntax is as follows:
from modname import name1[, name2[, ... nameN]]
For example, to import the fibonacci function of module fib, use the following statement:
from fib import fibonacci
(This statement does not Will import the entire fib module into the current namespace, it will only introduce the fibonacci in fib individually into the global symbol table of the module that executes this declaration.)
form.. .import* statement:
It is also feasible to import all the contents of a module into the current namespace. Just use the following statement:
from modname import *
This provides an easy way to import all projects in a module. However, this statement should not be overused.
For example, if we want to import everything in the math module at once, the statement is as follows:
from math import *
The above is what I want to explain today. The definition and usage of the import statement, just look at The explanations and examples I gave are just words on paper. Hands-on practice is the best way to verify what you have learned. Finally, I hope this article can bring some help to you who are learning python.
For more related knowledge, please visit the Python tutorial column on the php Chinese website.
The above is the detailed content of What is the import statement in python? what's the effect?. For more information, please follow other related articles on the PHP Chinese website!