Home > Article > Backend Development > Does the Python standard library need to be imported?
Does the python standard library need to be imported?
Needs to be imported. The library needs to be imported before use. The standard library means that it has been installed when Python is installed. alright.
The import library has two methods:
1. import modulename (keyword module name)
import random random.randrange(10)
Through this With this import, we can use the public functions, classes or properties in this module. The form used is modulename.funcname()
At the same time, import can import multiple modules in one line of statements at the same time, for example, import modulename1, modulename2, modulename3
2, from modulename import funcname (keyword module name keyword method name)
from random import randrange randrange(10)
This kind of import is more specific than the first one. It does not import the entire module, but imports a certain function in the module. class or attribute. Why is it imported like this? Because funcname is directly imported into the local name space. After the specific import, you can directly use the imported funcname when using it without adding modulename. in front of funcname. This is convenient. Much faster.
Recommended: Python Tutorial
The above is the detailed content of Does the Python standard library need to be imported?. For more information, please follow other related articles on the PHP Chinese website!