Python 官方文档:入门教程 => 点击学习
def personinfo(name,**info): print(name) print(info) for key in info: print(key) print(info[
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
--结束END--
本文标题: python3-可变参数
本文链接: https://lsjlt.com/news/191979.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0