Basic Python Tutorial (second edition) Learning Note function (Chapter 6th)
To create a function:
def function_name (params):
Block
Return values
Record function:
def function_name (params):
' NOTE ' #注释
Block
Return values
function_name.__doc__
Help (Function_name)
Return # no value returned
Position parameters and keyword parameters:
Keyword parameter to provide the name of the parameter:
def function_name (Name1=value1, name2=value2): #给参数提供了默认值
Block
Return values
Let the user provide any number of parameters:
def function_name (*params):
Block
Return values
def print_params (*params): #定义函数
Print params
Print_params (#调用函数)
Handle the collection of keyword parameters:
def function_name (**params):
Block
Return values
def print_params (**params): #定义函数
Print params
Print_params (x=1,y=2,z=3) #调用函数
def add (x, y): Return x+y
Params= (ON)
Add (*params)
Globals () [' Param_name ']
Locals () [' Param_name ']
Global X
Map () passes all the elements in a sequence to a function
Map (str, range (10))
Filter (func, seq)
Lambda expression
Filter (lambda x:x.isalnum (), seq)
Reduce () uses the first two elements of a sequence in conjunction with a given function, and continues to use their return value and the 3rd element until the entire sequence is processed.
Basic Python Tutorial (second edition) Learning Note function (Chapter 6th)