Skip to content

Instantly share code, notes, and snippets.

@myusuf3
Created March 12, 2011 01:53
Show Gist options
  • Save myusuf3/866945 to your computer and use it in GitHub Desktop.
Save myusuf3/866945 to your computer and use it in GitHub Desktop.
Global variables in Python
globvar = 0
def set_globvar_to_one():
global globvar # Needed to modify global copy of globvar
globvar = 1
def print_globvar():
print globvar # No need for global declaration to read value of globvar
set_globvar_to_one()
print_globvar() # Prints 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment