Global variables in Python


/ Published in: Python
Save to your folder(s)



Copy this code and paste it in your HTML
  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

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.