Skip to content

Instantly share code, notes, and snippets.

@edenau
Created January 18, 2020 21:25
Show Gist options
  • Save edenau/d20af23b693aa0b61931823f734d75c7 to your computer and use it in GitHub Desktop.
Save edenau/d20af23b693aa0b61931823f734d75c7 to your computer and use it in GitHub Desktop.
a = 1 # a variable
def increment():
a += 1
return a
def increment2():
global a # can make changes to global variable "a"
a += 1
return a
increment() # UnboundLocalError: local variable 'a' referenced before assignment
increment2() # returns 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment