Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/360.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python递归函数即使在使用返回函数后也不返回任何类型?_Python_Function_Return_Return Value - Fatal编程技术网

Python递归函数即使在使用返回函数后也不返回任何类型?

Python递归函数即使在使用返回函数后也不返回任何类型?,python,function,return,return-value,Python,Function,Return,Return Value,我正在处理此代码段: result=[] def function(i,x,Tree,result): if isinstance(Tree,ExNode): return 0 a=Tree.tempatt if x[a]<Tree.tempval: return result.append(Tree.val), function(i,x,Tree.left,result) else:

我正在处理此代码段:

result=[]
def function(i,x,Tree,result):
    if isinstance(Tree,ExNode):     
        return 0    
    a=Tree.tempatt
    if x[a]<Tree.tempval:            
        return result.append(Tree.val), function(i,x,Tree.left,result)
    else:                   
        return result.append(Tree.val), function(i,x,Tree.right,result)
result=[]
def函数(i、x、树、结果):
如果isinstance(树,ExNode):
返回0
a=树。tempatt
如果x[a]这样写

result=[]
def function(i,x,Tree,result):
    if isinstance(Tree,ExNode):     
        return 0    
    a=Tree.tempatt
    if x[a]<Tree.tempval:  
        result.append(Tree.val), function(i,x,Tree.left,result)  
        return result
    else:
        result.append(Tree.val), function(i,x,Tree.right,result)          
        return result
result=[]
def函数(i、x、树、结果):
如果isinstance(树,ExNode):
返回0
a=树。tempatt

如果x[a]
append
不返回任何值。是的,谢谢,我检查过了,但是还有什么结构可以用来获取从递归循环返回的所有值呢?有什么建议吗?如果要返回组合列表,可以返回
result+[Tree.val]
。或者您可以附加到
result
,然后返回
result
。不要写“return”行,而是写:“result.append(Tree.val)、function(i,x,Tree.left,result)”然后是“return result”@sadafShafi:非常感谢。我理解我的错误……你的方法好多了