Functional programming The most important thing is to enhance the reusability and readability of code
Ii. Definition and use
def 函数名(参数):
...
函数体
...
The definition of a function has the following main points:
- def: A keyword that represents a function
- Function name: the names of functions, which are called later by function name
- Function Body: A series of logical calculations in a function, such as sending a message, calculating the maximum number in [11,22,38,888,2], etc...
- Parameters: Providing data for the function body
- Return value: Once the function has finished executing, it can return data to the caller.
In the above points, it is more important to have parameters and return values:
There are three different parameters to the function:
- General parameters
- Default parameters
- Dynamic parameters
# ######### define function ######### # name is called the formal parameter of function func, abbreviation: formal parameter def func (name): print name # ######### Execute function ######### # func ( " Span style= "COLOR: #800000" >wupeiqi " ) Normal parameters
def func (name, age =): print"%s:%s" %(name,age) # Specify parameter func ('wupeiqi', +)# Use default parameter func ('Alex') Note: Default parameters need to be placed at the end of the parameter list
Python 3.5 (11) function