python中函数返回多个值

it2024-07-25  75

用ipython运行情况如下:
# 新建一个函数 In [1]: def nums(): ...: a = 11 ...: b = 22 ...: c = 33 ...: return [a,b,c] #以列表的方式返回 ...: #调用函数 ...: nums() ...: ...: #函数返回值 Out[1]: [11, 22, 33] # 新建一个函数 In [2]: def nums(): ...: a = 11 ...: b = 22 ...: c = 33 ...: return (a,b,c) #以元祖的方式返回 ...: #调用函数 ...: nums() ...: ...: #函数返回值 Out[2]: (11, 22, 33) # 新建一个函数 In [3]: def nums(): ...: a = 11 ...: b = 22 ...: c = 33 ...: return a,b,c #以元祖的方式返回的另一种形式 ...: #调用函数 ...: nums() ...: ...: #函数返回值 Out[3]: (11, 22, 33)

转载于:https://www.cnblogs.com/littlesuns/p/9930813.html

最新回复(0)