[Tutor] global list

Denis Heidtmann denis.heidtmann at gmail.com
Thu Apr 24 01:46:49 CEST 2014


In a coursera python course video the following code was presented:

a = [4,5,6]

def mutate_part(x):
    a[1] = x

mutate_part(200)

The presenter said something like "a is a global variable, so a becomes

[4,200,6] after running mutate_part(200)."

Indeed it does, but why does this work without specifying a as global
within mutate()?
My thinking was that an "undefined" error should have been raised.

Help me understand.  Thanks,

-Denis


More information about the Tutor mailing list