1. Creation of functions
def # definition Print ('hellow') # Execution Code of the function Retrun 1 # return value fun () # Execute function
2. Parameters of the function
Common parameters: To enter parameters in order
def Fun (a,b,c): Print (a) Print (b) Print (c) return afun (11,22,33)# output:One# output:# Output:33
Specify parameters: Input parameters can not be entered in sequence
def Fun (a,b,c): Print (a) Print (b) Print (c) return Afun (b=1,a=3,c=44)# output: 3 1
Default parameter: parameter must be placed at the end of the parameter when there are default parameters
def Fun (A,b= " old driver " =a+b return Temret =fun ( " i am " ) print # Span style= "COLOR: #008000" > output: I am old driver
#如果不想默认值
def fun (a,b= old driver ):
Tem=a+b
return tem
Ret=fun ("I Am","SB")
Print (ret)
#输出: I am SB
Dynamic parameters
*args: Representing tuples
**kwargs: Represents a dictionary
def Fun (a,*args,**Kwargs): print(A,args,kwargs) Fun (23,1,2,3,4,k1=33,k2= 5)# output (1, 2, 3, 4) {' K2 ': 5, ' K1 ':
function usage in Python