Posted By

magicrebirth on 09/28/10


Tagged

variable global


Versions (?)

Global variables in Python


 / Published in: Python
 

URL: http://stackoverflow.com/questions/423379/global-variables-in-python

  1. globvar = 0
  2.  
  3. def set_globvar_to_one():
  4. global globvar # Needed to modify global copy of globvar
  5. globvar = 1
  6.  
  7. def print_globvar():
  8. print globvar # No need for global declaration to read value of globvar
  9.  
  10. set_globvar_to_one()
  11. print_globvar() # Prints 1

Report this snippet  

You need to login to post a comment.