2013-03-19 58 views
0

我想從一個函數返回成獨立的變量存儲環形數據。這裏是我的代碼 請糾正我,如果錯了商店循環到Python的不同變量的數據?

功能:

def rawi(): 
     a = raw_input("enter value of a") 
     b = raw_input("enter value of b") 
     return a, b 

#calling the above function: 

c = rawi() 


for i in c: 
    print i 

我的期望輸出應該是這樣的: 變量1的值應爲從 變量2迴應該從B

返回的值

感謝

回答

5

你的意思是像下面這樣?

variable1, variable2 = rawi() 
+0

由於一噸,它的工作就像一個魅力 – 2013-03-19 16:12:02

-1

你的功能應該是這樣的,如果你要到C循環:

def rawi(): 
    a = raw_input("enter value of a") 
    b = raw_input("enter value of b") 
    return (a, b) #you can return tuple/list/whatever that stores multiple variables 
+1

我喜歡的括號,但它們不是嚴格必要的,因爲','操作符創建元組。 – dsh 2013-03-19 16:15:16