Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.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
带list的Python递归返回None_Python_List_Recursion - Fatal编程技术网

带list的Python递归返回None

带list的Python递归返回None,python,list,recursion,Python,List,Recursion,为什么这个递归函数返回None?请参见下面的文本?我不太明白我做错了什么 def foo(a): a.append(1) if len(a) > 10: print a return a else: foo(a) 您不返回else子句中的任何内容: In [263]: x = [] In [264]: y = foo(x) [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] In [265]: p

为什么这个递归函数返回None?请参见下面的文本?我不太明白我做错了什么

def foo(a):
    a.append(1)
    if len(a) > 10:
        print a
        return a
    else:
        foo(a)

您不返回else子句中的任何内容:

In [263]: x = [] In [264]: y = foo(x) [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] In [265]: print y None
    else:
        return foo(a)