"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
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
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
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