python3-可变参数-成都创新互联网站建设

关于创新互联

多方位宣传企业产品与服务 突出企业形象

公司简介 公司的服务 荣誉资质 新闻动态 联系我们

python3-可变参数

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

本文标题:python3-可变参数
文章位置:http://kswsj.cn/article/iedipd.html

其他资讯