Home > Backend Development > Python Tutorial > What is python import

What is python import

藏色散人
Release: 2019-07-01 11:18:37
Original
7016 people have browsed it

What is python import

Python's import is a very frequently used operation, which is an operation of using the code of another module in one module (almost all languages ​​have similar statements). The import statement is the most commonly used method, but it is not the only method. There are also importlib.import_module() and __import__() , etc.

import does two things:

● Search for the module with the name (in fact, the built-in __import__() method is used) and then initialize an object

● Bind the result to a local variable name (the default is the name of this module).

means that these two sentences are equivalent: import package as pk and pg = __import__('package')

It is worth noting that only calling __import__() will only execute Search actions, initialize the module object, and finally discard the object (because there is no assignment operation). It is easy to confuse the built-in __imoprt__() method with the import statement.

Related recommendations: "Python Tutorial"

The above is the detailed content of What is python import. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template