return statement doesnt return anything in python recursion

前端 未结 2 500
孤街浪徒
孤街浪徒 2021-01-23 22:58

The methods below look in a string to find if it has any python methods.

def there_is_a_call( string ): 
    return string.find(\'(\') > -1

def find_and_rem         


        
2条回答
  •  无人及你
    2021-01-23 23:24

    Some more explanation here.

    a = find_and_remove_functions( 'func() and some more()' , [] ) prints a list because there is a line print( found_functions ) being executed.

    a is assigned to the result of find_and_remove_functions and, since the function returns nothing after the set of recursive calls (see your else part doesn't have a return), it is assigned to None.

    Here's a simple example of what is happening:

    >>> def test():
    ...     print "test"
    ... 
    >>> a = test()
    test
    >>> print(a)
    None
    >>> a is None
    True
    

提交回复
热议问题