Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the ways for python to import modules?

Shulou Source: shulou.com Published: 2022-06-03 17:42:02 10月31日 Update

This article mainly shows you "what are the ways of python import module", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "what are the ways of python import module" this article.

1. Import the whole module, and the module name + period cannot be omitted.

# import module_nameimport fibo

2. Import a specific function in the module, and you don't need to use the module name + period to call the function.

Because the functions fib and fib2 have been explicitly imported in the import statement, you only need to specify their names when called.

# from module_name import function_namefrom fibo import fib, fib2 fib (10)

3. Import all functions in the module, which will import all functions except the name that begins with an underscore (_).

Note: in most cases, this use of * is generally not recommended because it may introduce an unknown set of names into the interpreter, usually resulting in poor readability of the code.

# from module_name import * from fibo import * fib (20) above are all the contents of this article entitled "what are the ways to import python modules?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Module function way content name article period learning help code just readability regular meeting beginning situation easy to understand more organization knowledge editing Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info MySQL OPPO Reno Xiaomi Redmi