热线电话:13121318867

登录
2019-01-19 阅读量: 792
python如何从列表或元组中解压缩参数

这里**解包了与它一起使用的字典,并将字典中的项作为关键字参数传递给函数。所以写“fun(1,** d)”相当于写“fun(1,b = 4,c = 10)”。

# A Python program to demonstrate packing of

# dictionary items using **

def fun(**kwargs):

# kwargs is a dict

print(type(kwargs))

# Printing dictionary items

for key in kwargs:

print("%s = %s" % (key, kwargs[key]))

# Driver code

fun(name="geeks", ID="101", language="Python")

Output :

<class 'dict'>
language = Python
name = geeks
ID = 101

应用程序和要点

1.用于套接字编程,以向服务器发送大量请求。

2.在Django框架中用于向视图函数发送变量参数。

3.有包装函数要求我们传入变量参数。

4.参数的修改变得容易,但同时验证不合适,因此必须小心使用它们。

0.0000
3
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子