Python: Function always returns None

前端 未结 4 776
迷失自我
迷失自我 2020-11-29 11:36

I have some Python code that basically looks like this:

my_start_list = ...

def process ( my_list ):
    #do some stuff

    if len(my_list) > 1:
                


        
4条回答
  •  广开言路
    2020-11-29 12:05

    You call process recursively but never ignore it's return value when you do. Add a return statement to pass on the return value::

    def process ( my_list ):
        #do some stuff
    
        if len(my_list) > 1:
            return process(my_list)
        else:
            print(my_list)
            return my_list
    

    Now, when len(my_list) > 1 is True, you actually pass on the return value of the recursive call.

提交回复
热议问题