What is the recommended way to avoid the mutable default argument pitfall in Python?
Correct answer
A. Use None as the default and create the list inside the function
5 views
A. Use None as the default and create the list inside the function
5 views
Setting lst=None and creating a new list inside the function avoids shared state.
Asked in: Python Interview Functions
https://docs.python.org/3/tutorial/controlflow.html#defining-functionsNot sure why the answer is A? Ask here and get an explanation.