Created
July 2, 2020 09:56
-
-
Save jamiebullock/a2884b7e9194a3a15b2fcecf754c35ff to your computer and use it in GitHub Desktop.
Counter class 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: | |
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