I ran into a similar situation like the following (ipython session).
Can anyone please explain why the behavior?
Thanks in advance.
In [11]: def foo(b=[]):
: b.append(3)
: return b
:
In [12]: foo()
Out[12]: [3]
In [13]: foo()
Out[13]: [3, 3]
In [14]: foo([])
On Wed, Apr 2, 2008 at 10:59 PM, [EMAIL PROTECTED] wrote:
I ran into a similar situation like the following (ipython session).
Can anyone please explain why the behavior?
Of course.
From http://docs.python.org/ref/function.html:
Default parameter values are evaluated when the function
On Wed, Apr 2, 2008 at 3:59 PM, [EMAIL PROTECTED] wrote:
I ran into a similar situation like the following (ipython session).
Can anyone please explain why the behavior?
http://www.python.org/doc/faq/general/#why-are-default-values-shared-between-objects
Since you got bitten by this, you may
[EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
I ran into a similar situation like the following (ipython session).
Can anyone please explain why the behavior?
Thanks in advance.
In [11]: def foo(b=[]):
: b.append(3)
: return b
:
In [12]: foo()