Hello friends:

I saw the following example at
http://nafiulis.me/potential-pythonic-pitfalls.html#using-mutable-default-arguments
and
did not believe the output produced and had to try it for myself....

def foo(a,b,c=[]):
    c.append(a)
    c.append(b)
    print(c)

foo(1,1)
foo(1,1)
foo(1,1)

produces:
[1, 1]
[1, 1, 1, 1]
[1, 1, 1, 1, 1, 1]

One would expect the following output:
[1, 1]
[1, 1]
[1, 1]

Doesn't this valid the zen of python: "Explicit is better than implicit."  ?

Thanks!
Billy
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to