-1

I'm playing with recursive functions and I'm not figure out why the function is not return if the list is empty ([]) even if the print function before the return is executed.

def go(mylist):
if not mylist:
    print('Empty list')
    return 'List Empty'
else:
    print(mylist)
    mylist.pop()
    go(mylist)

print(go([1, 2, 3, 4, 5]))

I get return 'None' because a function without a a return always return 'None'

0

1 Answer 1

2

You have to return the value that you received from the recursive call:

return go(mylist)
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the very fast answer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.