2017-06-04 55 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.