0

I just wrote this codes on shell;

>>> def foo(x=[]):
    x.append(26)
    return x

>>> foo()
[26]
>>> foo()
[26, 26]
>>> foo()
[26, 26, 26]
>>>

It's astonishing. I don't understand this behaviour, however, in script it's normal. Why does this appending that element when called the function? I expected that only one [26] each time I call the function.

GLHF
  • 3,835
  • 10
  • 38
  • 83
  • It's impossible to find these duplicates when you first encounter this problem but it is such a coincidence you used the exact word *astonishing* just like the dupe – jamylak Jan 27 '15 at 11:15
  • @jamylak Yea I didn't know there is a duplicate actually how can I search this question to find is there a duplicate or not lol. For _astonishing_ I just found that in dictionary English is not my main ^^ – GLHF Jan 27 '15 at 12:33

0 Answers0