Why shouldn't you use an empty list as a default argument?
Default values for function arguments are evaluated only once when the function is defined, not each time it's called. Therefore, if you use a mutable data type (like a list) as a default argument, any modifications to this value will persist across subsequent calls to the function, leading to unexpected behavior.
An empty list is mutable, so using it as a default argument is not recommended. Instead, use None as the default value and create a new list inside the function if needed.
Page of .
Leave a comment
You must be logged in to leave a comment.
Log in or
sign up to join the discussion.
Comments (0)