2014-07-21 140 views

回答

3

通常的方法做,這是一個元組,它可以只使用與return

>>> def multi_return(): 
     return 1, 2, 3 

>>> multi_return() 
(1, 2, 3) 

您可以使用元組拆包綁定返回值來分隔名稱:

>>> a, b, c = multi_return() 
>>> a 
1 
>>> b 
2 
>>> c 
3 

或者,您可以return單個列表,其處理方式大致如下:

>>> def list_return(): 
     return [1, 2, 3] 

>>> list_return() 
[1, 2, 3] 
>>> a, b, c = list_return() 
>>> b 
2