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