Last active
July 2, 2020 09:55
-
-
Save jamiebullock/a149add37b98f276735dd779137d3090 to your computer and use it in GitHub Desktop.
Counter example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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