Wednesday, 28 August 2013

How to properly declare a an empty list as a default parameter [duplicate]

How to properly declare a an empty list as a default parameter [duplicate]

This question already has an answer here:
"Least Astonishment" in Python: The Mutable Default Argument 20 answers
I've been told I should use;
def some_method(self,a,b=[]):
etc...
instead of
def some_method(self,a,b=list()):
etc...
'just because' .. well, I want to know 'why'!
As far as I am aware, there is no real difference between the two?

No comments:

Post a Comment