So here we are passing 2 arguments to the function: 1) a just created object from the class (counter) and 2) a number (0).
def increment(c, num):
c.count += 1
num += 1
class Counter:
def __init__(self):
self.count = 0
counter = Counter()
number = 0
for i in range(0, 100):
increment(counter, number)
print(
"counter is "
+ str(counter.count)
+ ", number of times is "
+ str(number)
)
The result of the code is the following:
# counter is 100, number of times is 0
Why the 'number' variable does not increase, if the function clearly says:
num += 1
???