What is a function?
A program can contain more than one module, the more complex the program, the more modules and functions involved, the module subdivision contains more than one class, the concept of class in any object-oriented language is very important, in the class is the main is the inclusion of functions, functional implementation of a function of the code body, the function of the code the most basic encapsulation.
So multiple functions form a class, multiple classes form a module, and multiple modules form a program.
Main function, one entry for the whole program
Such as:
def Add (num01, num02):
return num01 + num02
def Sub (num01,num02):
return num01-num02
def Mul (num01,num02):
return NUM01 * num02
def Div (num01,num02):
return num01/num02
Print (Add (100,200))
Print can be printed, without the main function can also be run, the code will be scanned from the beginning to end, found that the whole is a function, will not execute, wait for the call. In order to make the code more readable, you should set a code for the program, the entire code is the main function,
the entry of the program main function , The code starts here to execute
Such as:
def Add (num01, num02):
return num01 + num02
def Sub (num01,num02):
return num01-num02
def Mul (num01,num02):
return NUM01 * num02
def Div (num01,num02):
return num01/num02
# Getting Started with the program, Main function
if __name__ = = "__main__":
Print (Add (100,2 00))
Demo : There is a green triangle in front, which represents the code for the sweep codes, and the command executes from this function.
Call the previously written function
Such as:
Import into the function module
Class
def function
Such as:
Import demo01 call demo01 inside the program
Choose Demo02 at the time of execution
Python:main function