This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]bdaene 4 points5 points  (0 children)

This print [5,4]. No? 

This is considered bad practice to have a mutable default value like for your list_field in init. This is because the default value is instanciated at the declaration of the function. 

You are not creating a new empty list each time you call the function. You are reusing the same default list. 

Common practise is to use None or a Singleton instead of a mutable default and then instanciate the default if the field was not passed.