#coding =utf8
__author__ = ' Administrator '
# When the parameters of the function are uncertain, you can use *args and **kwargs. *args does not have a key value, **kwargs has a key value
def Fun_var_args (Farg, *args):
print ' args: ', farg
For value in args:
print ' Another arg: ', value
# *args can be used as a list or tuple that can hold multiple variables
Fun_var_args (1, ' two ', 3, None)
#args: 1
#another Arg:two
#another Arg:3
#another Arg:none
def Fun_var_kwargs (Farg, **kwargs):
print ' args: ', farg
For key in Kwargs:
print ' Another keyword arg:%s:%s '% (key, Kwargs[key])
# MYARG1,MYARG2 and Myarg3 are considered key, and the sense **kwargs can be treated as a dictionary that holds multiple keys and value.
Fun_var_kwargs (1, myarg1= ' two ', myarg2=3, Myarg3=none)
Output
#args: 1
#another keyword Arg:myarg1:two
#another keyword Arg:myarg2:3
#another keyword Arg:myarg3:None
def Fun_args (Arg1, Arg2, ARG3):
print ' arg1: ', arg1
print ' arg2: ', arg2
print ' Arg3: ', Arg3
Myargs = [' 1 ', ' two ', None] # define List
Fun_args (*myargs)
Output
#arg1:1
#arg2: Two
#arg3: None
Mykwargs = {' arg1 ': ' 1 ', ' arg2 ': ' Two ', ' Arg3 ': None} # define Dictionary type
Fun_args (**mykwargs)
Output
#arg1:1
#arg2: Two
#arg3: None
# both have
def Fun_args_kwargs (*args, **kwargs):
print ' args: ', args
print ' Kwargs: ', Kwargs
args = [1, 2, 3, 4]
Kwargs = {' name ': ' Beginman ', ' age ': 22}
Fun_args_kwargs (Args,kwargs)
# args: ([1, 2, 3, 4], {' Age ': +, ' name ': ' Beginman '})
# Kwargs: {}
Fun_args_kwargs (1,2,3,a=100)
#args: (1, 2, 3)
#kwargs: {' A ': 100}
Fun_args_kwargs (* (1,2,3,4), **{' a ': None})
#args: (1, 2, 3, 4)
#kwargs: {' A ': None}