Skip to content

Instantly share code, notes, and snippets.

@jamiebullock
Last active July 2, 2020 09:55
Show Gist options
  • Save jamiebullock/a149add37b98f276735dd779137d3090 to your computer and use it in GitHub Desktop.
Save jamiebullock/a149add37b98f276735dd779137d3090 to your computer and use it in GitHub Desktop.
Counter example
class Counter:
def __init__(self): # define __init__ method passing self
self.count = 0 # set instance attribute count to 0
def increment(self): # define increment method passing self
self.count += 1 # add 1 to instance attribute count
c1 = Counter() # create Counter instance
c2 = Counter() # create another instance
c1.increment() # increment counter for c1
c1.count # count is 1
c2.count # count is 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment