educative.io

Quiz number 8: why not B)

‘values’ is a variable defined inside the function. how its pointer/object is stored and caught by the next function call? Can you please give more explanation? Thank you

Hi @Tess! This is a great question.

This is one of the most common Python pitfalls. Essentially, “A new list is created once when the function is defined, and the same list is used in each successive call.” to quote https://docs.python-guide.org/writing/gotchas/ (which is a great read btw)

Hence, values is defined once and then reused on every call, which is why previous numbers are retained.

Feel free to drop us any further comments or questions!

Regards,
Team Educative

Great explanation! Thank you!