global lists

andrea crotti kerny404 at gmail.com
Sun May 8 06:01:07 EDT 2005


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 el in a:
    el = el*2

This doesn't make any difference, if I do
def foo():
  global a
  a[0] = 4

But

def foo():
  global a
  for n in range(len(a)):
    a[n] = a[n]*2

Doesn't work either...
So I think that's pretty weird, why this happen?
I have to create a new list and assign it back to get it working??
Thaks



More information about the Python-list mailing list