热线电话:13121318867

登录
2019-06-25 阅读量: 454
如何在python中使用元祖返回多个值?

使用元组:元组是以逗号分隔的项目序列。它是使用或不使用()创建的。元组是不可变的。见对元组和列表的详细信息。

# A Python program to to return multiple

# values from a method using tuple

# This function returns a tuple

def fun():

str = "geeksforgeeks"

x = 20

return str, x; # Return tuple, we could also

# write (str, x)

# Driver code to test above method

str, x = fun() # Assign returned tuple

print(str)

print(x)

输出:

geeksforgeeks
20
0.0000
2
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子