Summary of python function parameters, python function parameters
Function Parameters in python include default parameters, keyword parameters, non-Keyword variable-length parameters (tuples), and keyword variable-length parameters (dictionaries)
Default parameters: When declaring a function, specify the default value of the parameter. Do not change the parameter when calling the function (use the default value)
Def foo (x): # default parameter
Print 'x is % s' % x
Keyword parameter:Y is 20 by default.
Def foo (x, y = 20): # keyword Parameter
Print 'x is % s' % x
Print 'y is % s' % y
Non-Keyword variable length parameter (tuples ):* Z receives a tuples.
Def foo (x, y = 20, * z): # default parameter
Print 'x is % s' % x
Print 'y is % s' % y
for myz in z:
print 'z: ', myz
Keyword variable length parameter (dictionary ):** W receives a dictionary.
Def foo (x, y = 20, * z, ** w): # default parameter
for wArg in w.keys(): print 'wArg %s: %s' % (wArg, str(w[wArg]))