SoFunction
Updated on 2024-10-29

Detailed Python syntax of the module Module

I. Definitions

Contains a range of data,function (math.),Documentation of the class,commonly referred to as.pywind up

II. Role

Let some related data, functions, classes are logically organized together, the use of logic is conducive to collaborative development of multiple people

III. Introduction

import (data)

import module name

1.grammatical:
import module name
import module name as nickname
as:为导入的成员起一个另外的nickname,Avoiding conflicts
2 corresponds English -ity, -ism, -ization:Importing a module as a whole into the current module
3.hypostasis:Using Variable Name Namesmodul01Associated Module Address
The first import method
# Create a new file and write the following code.
print("Module 1")

def fun01():
    print("Module 1 fun01.")

class MyClass02:
    def fun02(self):
        print("MyClass02")

# Create a new file with the following code.
import module01
module01.fun01()
my02 = module01.MyClass02()
my02.fun02()
output result:
module (in software)1
module (in software)1(used form a nominal expression)fun01
MyClass02
Process finished with exit code 0

from import

1.grammatical:
from module name importmember's name[as nickname]
2.hypostasis:Import the specified member into the current module scope
3.corresponds English -ity, -ism, -ization:将模块内的一个或者多个成员导入到当前模块的corresponds English -ity, -ism, -ization域
# Second import
from module01 import MyClass02
from module01 import fun01
fun01()
my02 = MyClass02()
my02.fun02()
output result
module (in software)1
module (in software)1(used form a nominal expression)fun01
MyClass02
Process finished with exit code 0

from module name import *

1.grammatical:
from module01 import *
2.hypostasis:Import all members of a given module into the current module scope.
3.Modules are underlined in the(_)Properties at the beginning,Will not be imported
# Third import
from module01 import *
fun01()
my02 = MyClass02()
my02.fun02()

summarize

That's all for this post, I hope it was helpful and I hope you'll check back for more from me!