python中函数返回多个值

用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)

猜你喜欢

转载自www.cnblogs.com/littlesuns/p/9930813.html