科技网

当前位置: 首页 >IT

python3-可变参数

IT
来源: 作者: 2018-11-14 18:09:56

def personinfo(name,**info):    print(name)    print(info)    for key in info:        print(key)        print(info[key])personinfo("zhangsang",age=25,***="man")personinfo("lisi",age=29,***="woman")
zhangsang{'age': 25, '***': 'man'}age25***manlisi{'age': 29, '***': 'woman'}age29***woman
def personinfo(name,**info):    print(name)    print(info)    for key in info:        print(key)        print(info[key])students={"age":32,"***":"man"}personinfo("zhangsang",age=25,***="man")personinfo("lisi",age=29,***="woman")personinfo("wangwu",**students)
zhangsang{'age': 25, '***': 'man'}age25***manlisi{'age': 29, '***': 'woman'}age29***womanwangwu{'age': 32, '***': 'man'}age32***man
def personinfo(name,*info):    print(name)    print(info)    for name,value in info:        print(name),        print(value)students=[("age",32),("***","man")]personinfo("zhangsang",("age",25),("***","man"))personinfo("wangwu",*students)
zhangsang(('age', 25), ('***', 'man'))age25***manwangwu(('age', 32), ('***', 'man'))age32***man

文章来源于互联网,非作者本人观点,如有侵权等违规现象,请找作者联系删除。

相关推荐