table of Contents
Chapter VII basis, function 02
First, the definition of the function
Definition: In the program, function like a feature tool, the tool is ready to define a function, encounter scenarios that make use of the calling function
Second, why use the function
To solve the following three questions:
Redundancy program
Bearded expansion poor
Poor readability of the program
Third, how to use the function
Define, after calling
Defined Functions
def 函数名(param1、param2……): """ 函数功能的描述信息 :param1:描述 :param2:描述 :return:返回值 """ code 1 code 2 code 3 ... return 返回值 调用函数
函数名(param1、param2……)
Function definition stage
def func(): bar() # 不属于语法错误,不会报错 print('*'*10)
Function call stage
def bar(): print('from bar') def foo(): print('from foo') bar() foo() ''' from foo from bar '''
def foo(): print('from foo') bar() def bar(): print('from bar') foo() ''' from foo from bar '''