‘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)
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!
Great explanation! Thank you!