Skip to content

Instantly share code, notes, and snippets.

@jamiebullock
Created July 2, 2020 09:56
Show Gist options
  • Save jamiebullock/a2884b7e9194a3a15b2fcecf754c35ff to your computer and use it in GitHub Desktop.
Save jamiebullock/a2884b7e9194a3a15b2fcecf754c35ff to your computer and use it in GitHub Desktop.
Counter class example
class Counter:
count = 0 # class attribute count
def increment(): # define method to increment count
count += 1
Counter.count # count is 0
Counter.increment() # call the method increment()
Counter.count # count is 1
counter = Counter() # create instance of Counter
counter.count # class attribute... count is still 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment