If you have a hand, you will use Python custom modules

Mondo Technology Updated on 2024-02-20

1.Custom modules

Custom modules are generally encapsulated according to your own needs in the project.

The project has customized a module, modulepy

name = "Zhang San"age = 23weight = 160height = 187def test():print("Methods of testing")def demo():print("Angel's tears")def fn():print("Mice love rice")
2.Custom module use

Import a custom module by importing it

import module access to the variable print(modulename)print(module.age)print(module.weight)print(module.height) calls the function moduletest()module.demo()module.fn()
By from....import...Import variables and functions that are commonly found in the module module.

from module import * * represents a wildcard, which represents all the contents in the moduleprint(name)print(age)print(weight)print(height)test()demo()fn().
Import variables or functions in a module via the module name from (exact import).

from module import name,age,demo,fnprint(name)print(age)demo()fn()
3.Summary

In a Python project, you can import custom modules and access the variables and functions in them. You can import everything in a module with a wildcard *, or you can import a specific variable or function. Custom modules can be encapsulated according to project requirements to achieve modular organization and management.

February** Dynamic Incentive Program

Related Pages