[英]I am returning a list from my function, but when I print that returned list, it prints NONE
def f(N, end):
if end==-1:
N=[1]+N
print (N)
return (N)
if N[end]!=9:
N[end]+=1
return (N)
if N[end]==9:
N[end]=0
end-=1
print (N)
f(N,end)
L=[9,9,9,9,9]
print(f(L, len(L)-1))
You are missing the return clause in the second if statement您缺少第二个 if 语句中的 return 子句
if N[end]!=9:
N[end]+=1
return (N)
if N[end]==9:
N[end]=0
end-=1
print (N)
return f(N,end)
By fixing your code like that it should work通过修复您的代码,它应该可以工作
你的函数在你的第三个if
语句上没有return
语句(这就是为什么打印None
,默认情况下你的函数返回None
)它只会改变你的列表N
( L
),如果你打印你的列表L
你会看到结果是[0, 0, 0, 0, 0]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.