the global keyword:

Marcin Rak mrak at sightlineinnovation.com
Sat Jun 11 20:12:21 EDT 2016


On Saturday, 11 June 2016 18:51:11 UTC-5, Random832  wrote:
> On Sat, Jun 11, 2016, at 19:44, Marcin Rak wrote:
> > So my question is, how the heck is it possible that I get 5 as the last
> > value printed? the global test_var (global to Test.py) I set to 44 when I
> > ran some_function()???  does anyone have a clue they could throw my way?
> 
> Importing a variable from a module copies its value into your own
> module's variable. Updates to the source module's variable will not be
> reflected in your module.

As I suspected.  Nice to have it confirmed.  
So it copies any imported variable that is of simple type (string, int, float...)
What about variables that are user defined classes?  Are they referenced or copied?



More information about the Python-list mailing list