Content Today
-
Function definition
-
Function call
-
-
Function parameters
Function definition
# A function of data calculated by defining the length, def keywords, count_len function name
DEF count_len ():
LST = [. 1, 2,. 5]
COUNT = 0
for I in LST: COUNT =. 1 + # by function name call count_len ()
Function's return value
return_len DEF ():
return 'len' A = return_len () Print (A) return: # 1.return can return any type of data # 2 is returned in the form of a plurality of content tuple # 3 below is not performed, and will terminate the current function does not write or do not write the # 4 return, return None
Function parameters
Yue DEF (App1, App2, App3, APP4):
Print (App1)
Print (App2)
Print (App3)
Print (APP4)
Yue ( 'QQ', 'Weixin', 'taobao', 'zhifubao')
Function parameters:
-
Parameter: the definition of the time parameter definitions
Location parameters: one- keyword arguments: carry out mass participation by name mix parameters: use with positional parameters and keyword arguments
-
Argument: The actual argument passed
Location parameters: one- keyword arguments: carry out mass participation by name mix parameters: use with positional parameters and keyword arguments
-
Parameter passing: the value is passed to the function when calling the function defined is called transfer process parameters
important point
Precautions: Parameter name can not be repeated, priority should not be placed upside
position parameter> parameter default
position is a one-parameter
after parameter passing, you can not use the
return can not terminate the loop
Ternary operator
c = a if a > b else b
Results condition is satisfied (a) the condition (if a> b else) (b) Results condition is not satisfied