2017-06-04 71 views

回答

2

沒有功能,所以你不能使用返回。您可能會包裹代碼def

d={1:10,2:20,3:30} 

def return_30(d): 
    for a,b in d.items(): 
    if b==30: 
     return a 

而且我改名dictd,因爲dict是該類型的名稱,當你重新定義它,你無法訪問原始dict

0

for循環,不是函數。

def function(): 
    print(1+2) # Im inside the function, return keyword here is valid 

# I'm outside the function. 
for x in range(10): 
    print(x) 
    #This is not a function, return keyword here is invalid.