【发布时间】:2013-10-19 06:53:54
【问题描述】:
这是我写的一个函数:
def conc(i,s,y):
if sheet.cell(i+1,0).value != sheet.cell(2,0).value :
# print s
rtrns = s
# print rtrns
return rtrns
else:
if i==list1[len(list1)-1]:
while i<(sheet.nrows):
# print i
s = s + " " + unicode(sheet.cell(i,y).value).encode('cp1252', 'replace')
i+=1
# print s
rtrns = s
# print rtrns
return rtrns
else:
s = s + " " + unicode(sheet.cell(i+1,y).value).encode('cp1252', 'replace')
#return s
conc(i+1,s,y)
在上述函数中,当我在第一个 if 块中打印 rtrns 的值时,它会显示我需要的值。
但是当我调用函数时
c = conc(x,c,2) #where x fetches an integer value as an index from a list
print c
它返回None
【问题讨论】:
-
你在 else 子句中的 return 语句在哪里?
-
缩进有什么问题?而 else 块不需要 return 语句,它再次递归调用该函数,直到它满足具有 return 语句的两个块之一
-
'def' 和 'if' 在同一缩进级别???
-
您的函数不能保证返回。在某些情况下它不会返回任何东西。
-
@user2799617:这是我在此处复制粘贴代码时发生的错误。
标签: python python-2.7 return