重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

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://cqcxhl.com/article/iedipd.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP