热线电话:13121318867

登录
2019-06-24 阅读量: 481
python如何压缩数据

考虑我们有一个接收四个参数的函数的情况。我们想调用这个函数,我们有一个大小为4的列表,包含函数的所有参数。如果我们只是将列表传递给函数,则调用不起作用。

我们可以使用*解压缩列表,以便它的所有元素都可以作为不同的参数传递。

# A sample function that takes 4 arguments

# and prints the,

def fun(a, b, c, d):

print(a, b, c, d)

# Driver Code

my_list = [1, 2, 3, 4]

# Unpacking list into four arguments

fun(*my_list)

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

发表评论

暂无数据
推荐帖子