a basis function liter python day9 order (1)

Function 
readability reusability strong
def function name ():
function body
return the return value of
all the functions defined not only will certainly not be invoked to perform
call-before-defined

function name () # does not receive the return value
return value of the function name = ( ) # receive the return value

return value
does not return a value: the default return None
not write return: code execution within the function is completed automatically end
write-only return: the end of a function
return None
return a value: the end of the function and returns a value, it can be any value
return multiple values: a plurality of values separated by commas, can be received when a receiving variable (tuples), receiving a plurality of variables may be equivalent amount

DEF F (a):
return 'chestnut'

RET = f ( 'apple')
Print (F ( 'apple'))

parameter
parameter definition function when the
positional parameters: must pass
* args: a plurality of dynamic parameters may be received at any location parameters passed by
the default parameters: can not pass - trap
** kwargs: dynamic parameter can take any number of parameters passed by keyword
when calling function arguments
According to the position-parameters
follow the keyword-parameters
can be mixed prior location parameter must pass keyword parameters
can not be repeated to assign a parameter

def wahaha (* args):
Print (args)

# wahaha (1,2,3,4)
L = [1,2,3,4]
wahaha (* l)



qqxing DEF (K, L = {}): 
# l.append (. 1)
L [K] = 'V'
Print (L)

qqxing (. 1) # [. 1]
qqxing (2) # [1,1]
qqxing ( 3) # [1,1,1]

# if the value of the default parameter is a variable data type,
# then every call functions,
# if you do not pass a value to the public this type of data resources





Guess you like

Origin www.cnblogs.com/wang-tan/p/11041858.html