The concept of function, a function is a code set that organizes code blocks with independent functions into a whole, so that it has special functions
The role of functions, the use of functions can enhance the reusability of the code and improve the efficiency of programming
To use a function, a function must be created before it can be used. This process is called a function definition. After the function is created, it can be used. The use process is called a function call
Function definition and call:
def function name(Formal parameter 1, Formal parameter 2): #definition
... Function body
Function name(Actual parameter 1, actual parameter 2) #transfer
Example, define a sum function
def sum_1(x,y): #Define a named sum_Function of 1, whose parameters are x and y
z = x + y #Function body, which is the specific operation performed inside the function
return z #The return value of the function
When calling a function, just call the function name directly
sum_1(10,22)
Output result
32
Knowledge point expansion:
Function body
So far, this article on what is the function body of python is introduced here. For more related python function bodies, please search for the previous articles of ZaLou.Cn or continue to browse the related articles below. Hope you will support ZaLou more in the future. .Cn!
Recommended Posts