Python programming skills 2. python programming skills
Modularization-this is what our programmers dream of. modularization can avoid repeated manufacturing wheels.
At the same time
The module enables you to logically organize your Python code segments.
Assigning relevant code to a module makes your code easier to use and understand.
The module is also a Python object and has random name attributes for binding or reference.
Simply put, a module is a file that saves Python code. The module can define functions, classes, and variables. The module can also contain executable code.
Take the output as an example:
Encapsulate the printed data as a module. Each call to the module outputs the text starting with hello.
Module code:
Vim demoModule1.py
The content is as follows:
#! /Usr/bin/python
#-*-Coding: UTF-8 -*-
# Definition module: begin:
Def sayHello (hello ):
Print "hello,", hello
Return ## end definition end
The functions of the module are as follows:
#! /Usr/bin/python
#-*-Coding: UTF-8 -*-
# Functions defined in demoDE. py of the import module
Import demoModule1
# Call function in demoDEF. py
DemoModule1.sayHello ("haha ")
### This call method is the wrong sayHello ("++ 1234567 ++ ")
Run and output:
Error summary:
This is a forgotten addition: