python 在可变参数中使用字典和列表

python 在可变参数中使用字典,代码如下

def showdict(**kargs):
    for item in kargs.items():
        print(item)
user_dict={'alice':10,'bob':12}
showdict(**user_dict)  

调用时要加上两个星号

与此类似,在可变参数中使有列表,

def showlist(*arg):
    for item in arg:
        print(item)          
showlist('alice','peal')
username=['jerry','pet']
showlist(*username)

结果为

alice
peal
jerry
pet

你可能感兴趣的:(知识点)