a clarification on the "global" statement sought

Charles T. Smith cts.private.yahoo at gmail.com
Fri Mar 11 04:09:19 EST 2016


On Fri, 11 Mar 2016 08:31:22 +0000, Mark Lawrence wrote:

> Never. Hopefully this
> http://www.python-course.eu/python3_global_vs_local_variables.php can
> explain it better than I can :)


The article is good, I'm glad to have confirmed what I have so empirical
stumbled over.
... Irrespective of the "python-speak" (or to be fair,
evangelical-speak):

  "Python deals with variables the other way around.
   They are local, if not otherwise declared.
   ...
    def f(): 
        print(s) 
    s = "I love Paris in the summer!"
    f()
    ...
    As there is no local variable s, i.e. no assignment to s, the value
    from the ***global*** variable s will be used."

Indeed "maverick": that a variable can be an undefined global
and then only appears as such when assigned to, has caused me
no end of grief.

Nevertheless, python is still a fun language to program in.



More information about the Python-list mailing list