[New-bugs-announce] [issue18127] Strange behaviour with default list argument

Poul-Henning Kamp report at bugs.python.org
Mon Jun 3 21:38:11 CEST 2013


New submission from Poul-Henning Kamp:

I'd like to nominate this piece of code as candidate for the next round of "Most unexpected python behaviour" awards:

    def foo(a, x = []):
        x.append(a)
        return x

    print(foo(1))
    print(foo(2))

I expected the output to be:
    [1]
    [2]
but I get:
    [1]
    [1, 2]

Bug?  (If not, I'd *love* to read the rationale for this behaviour...)

----------
messages: 190557
nosy: bsdphk
priority: normal
severity: normal
status: open
title: Strange behaviour with default list argument
type: behavior
versions: Python 2.7, Python 3.2

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue18127>
_______________________________________


More information about the New-bugs-announce mailing list