Python 函数传递list,传递dict 以及*args和**kargs

Python 函数传递list,传递dict 以及*args和**kargs

函数之间传递list:

复制代码
def show(ll):
    for i in ll:
        print(i)
         
show(['chen','hang','wang','yadan'])
#==========================================
chen
hang
wang
yadan
复制代码

 

*args:输入数据长度不确定,通过*args将任意长度的参数传递给函数,系统自动将任意长度参数用list(tuple定长,特殊的list)表示

复制代码
def show(*args):
    for i in args:
        print(i)
        
show('chen','hang','wang','yadan')
#=============================================
chen
hang
wang
yadan
复制代码

**kargs:输入数据长度不确定,系统自动将任意长度参数用dict(字典)表示

复制代码
def show(**kargs):
    for i in kargs.items():
        print(i)

show(name='hangge',age=25,sex='man',school='wust')
#============================================
('name', 'hangge')
('school', 'wust')
('sex', 'man')
('age', 25)
复制代码

函数之间传递dict:

def show(**kargs):
    .....

user={‘chen’:1,'hang':2,'wangyadan':3}
show(**user)
posted @ 2018-06-07 09:00  PKICA  阅读(3314)  评论(0编辑  收藏  举报