【发布时间】:2020-09-25 15:58:35
【问题描述】:
我们先看代码-
def findlinks():
mylinks=[]
if (condition):
for x in range(int):
if x==(int):
#some operation goes here
else:
#some operation goes here
return mylinks,1
else:
for x in range(int):
if x==(int):
#some operation goes here
return mylinks,0
else:
#some operation goes here
links=[]
while (True):
first,second=findlinks()
links=links+first
if second==1:
pass
elif second ==0:
break
问题出在while loop。它永远不会运行多次。我认为这是因为当我从function 返回时,它会从function 和loop 中退出。
任何替代方法来解决这个问题?还是对代码进行任何修改?
【问题讨论】:
-
@TomKarzes 它不会等待函数的结果。 While 循环已失效。
-
哦,对不起,我看错了。那么
while循环将在second等于0时中断。 -
如果您能提及代码的目标,我将不胜感激。您的代码更像是伪代码,很难确定目的。请记住,对您的函数的调用必须返回适当的
second参数。
标签: python python-3.x function loops return