Teaching python (programming) to children

Hung Jung Lu hungjunglu at yahoo.com
Tue Nov 6 17:28:26 EST 2001


I believe I have said time and again about namespace and dictionary.
The examples I have given ('from xyz import *' and the 'global') are
just, examples. The root of the problem is not the 'from' statement
nor the 'global' statement. Python mailing list has tons and tons of
other examples of beginners running into namespace troubles.

#---------------------
def flipflop(x):
    if x == []:
        x.append(1)
    else:
        x = []

a = []
flipflop(a)
print a
flipflop(a)
print a
#---------------------
output:
[1]
[1]

In the above example, the 'global' statement plays no role. Nested
scope is not the problem. Not understanding the namespace mechanism is
the problem.

The root of the non-trivialness is the namespace structure, not any
particular Python statement or keyword. If you think you can explain
to beginners the above example, more than a few dozen times, without
getting exhausted, then I think you will be highly admired. :)

Hung Jung



More information about the Python-list mailing list