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)