Pergunta de entrevista da empresa Deliveroo

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

Resposta da entrevista

Sigiloso

13 de out. de 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.