I&C SCI 32 Lecture Notes - Lecture 8: Init
Document Summary
# this module defines a class called counter, which is a kind of object. # called a counter, whose goal is to count how many times its count # its count and returns it, so each time you call count, you"ll receive. # a value one greater than the value you received the previous time. # is also possible to reset the counter and to peek at its count (i. e. , # counter objects have one private attribute, _count, which specifies. # how many times its count() method has been called. # if you run this module in idle, you would be able to do this in the. """initializes a counter with a count of zero""" self. _count = 0 def count(self) -> int: """increments and returns the count""" self. _count += 1 return self. _count def peek(self) -> int: """returns the count without updating it""" return self. _count def reset(self) -> none: