如何从函数(python)返回标志和结果?



让我们先看看代码-

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回来时,它既functionloop

有什么替代方法可以解决这个问题吗? 或对代码进行任何修改?

很难说你想实现的目标到底是什么。

如果要在循环完成后返回,可以执行以下操作:

def func():
list = []
if condition:
flag = 1
# loop here, do something with the list
else:
flag = 0
# loop here, do something with the list
return list, flag

最新更新