Does the Python standard library need to be imported?

angryTom
Release: 2020-02-07 09:22:50
Original
6349 people have browsed it

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)
Copy after login

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)
Copy after login

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!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!