ast nom...@invalid.com 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
test()
2
I understand that the author wants to implement a global
variable
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
test()
2
I understand that the author wants to implement a global
variable x . It would
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 write
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