global lists
Dan Christensen
jdc at uwo.ca
Mon May 9 16:17:15 EDT 2005
andrea crotti <kerny404 at gmail.com> writes:
> Hi everbybody again,
> I have a little "problem", I don't understand the reason of this:
>
> a = [10,1,2,3]
> def foo():
> global a
> for n in range(len(a)):
> a[n] = a[n]*2
If I type the above, and then call foo, I get what looks like
reasonable output:
In [1]:a = [10,1,2,3]
In [2]:def foo():
.2.: global a
.2.: for n in range(len(a)):
.2.: a[n] = a[n]*2
.2.:
In [3]:foo()
In [4]:print a
[20, 2, 4, 6]
However, you didn't say what you expected, so I'm not sure what bug
I'm looking for!
Dan
More information about the Python-list
mailing list