Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand the Module module in Python syntax

2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Python syntax Module module how to understand, I believe that many inexperienced people are helpless about this, this article summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.

A file that defines a series of data, functions, and classes, usually ending in.py.

Let some related data, functions, and classes be logically organized together, and use logic to facilitate multiplayer collaborative development.

3. Import 1.import module name 1. Syntax: import module name import module name as alias as: play another alias for imported members to avoid conflicts 2. Role: import a module as a whole into the current module 3. Essence: use variable name modul01 to associate module address The first import method #Create a new file of module01.py and write the following code print("module 1")def fun01(): print("fun01 of module 1")class MyClass02: def fun02(self): print ("MyClass02")#Create another demofour.py file and write the following code import module01module01.fun01() my02 = module01.MyClass02()my02.fun02() Output result: module 1 module 1 fun01 MyClass02 Process finished with exit code 0from import1. Syntax: from module name import member name [as alias]2. Essence: import specified member into current module scope 3. Role: Import one or more members of a module into the scope of the current module #Second import method from module01 import MyClass02from module 01 import fun01() my02 = MyClass02()my02.fun02() Output result module 1 fun01MyClass02Process finished with exit code 0from module name import *1. Syntax: from module01 import *2. Essence: Import all members of the specified module into the current module scope3. Module attributes that begin with an underscore (_) will not be imported #The third way to import from module01 import * fun01 () my02 = MyClass02 ()my02.fun02() After reading the above, do you know how to understand Module modules in Python syntax? If you still want to learn more skills or want to know more related content, welcome to pay attention to the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report