Re: Curious function argument

2014-11-27 Thread Akira Li
"ast" writes: > Hello > > I saw in a code from a previous message in this forum > a curious function argument. > > def test(x=[0]): > print(x[0]) ## Poor man's object > x[0] += 1 > >>>> test() > 0 >>>> test() > 1 &g

Re: Curious function argument

2014-11-15 Thread Steven D'Aprano
ast wrote: > Hello > > I saw in a code from a previous message in this forum > a curious function argument. > > def test(x=[0]): >print(x[0]) ## Poor man's object >x[0] += 1 > >>>> test() > 0 >>>> test() > 1 >>>&g

Re: Curious function argument

2014-11-12 Thread Denis McMahon
On Wed, 12 Nov 2014 14:07:14 +0100, ast wrote: [function def with mutable default parameter] > I understand that the author wants to implement a global variable x . It > would be better to write 'global x' inside the function. It may not be the case that the purpose was to implement a global va

Curious function argument

2014-11-12 Thread ast
Hello I saw in a code from a previous message in this forum a curious function argument. def test(x=[0]): print(x[0]) ## Poor man's object x[0] += 1 test() 0 test() 1 test() 2 I understand that the author wants to implement a global variable x . It would be better to