Sollicitatievraag bij Deliveroo

What problem could occur is an empty list is used as default argument to a python function

Antwoord op sollicitatievraag

Anoniem

13 okt 2022

Python function are compiled whenever they first run and default arguments values are evaluated. Subsequent call to the function do not reevaluate the function. Hence, using list (or other mutables) would result in changes persisting across function calls i.e the list would not be empty across each calls but rather grow in size.