Teaching python (programming) to children

David Bolen db3l at fitlinxx.com
Tue Nov 6 16:06:54 EST 2001


hungjunglu at yahoo.com (Hung Jung Lu) writes:

> How soon does a beginner run into the following problem? (see also the
> "How much is set in stone?" thread)
> 
> #------------------
> flag = 0
> 
> def f(x):
>     flag = 1
>     return 2*x
> 
> y = f(3)
> print y, flag
> #------------------
> output: 
> 6 0
> 
> I'd say, most run into this problem soon after they learn to use
> functions. It does not matter whether they have seen any other
> programming language before or not.

Hmm, I'd like to think that learning to use functions would involve
local variables far more than globals.  Thus, on the less common case
where you (a) were using globals and (b) needed to overwrite the
global within a local scope, it shouldn't be too hard to introduce the
concept and the global keyword without causing overuse.

--
-- David
-- 
/-----------------------------------------------------------------------\
 \               David Bolen            \   E-mail: db3l at fitlinxx.com  /
  |             FitLinxx, Inc.            \  Phone: (203) 708-5192    |
 /  860 Canal Street, Stamford, CT  06902   \  Fax: (203) 316-5150     \
\-----------------------------------------------------------------------/



More information about the Python-list mailing list