I have this code:
class Doh:
ctr = 0;
def __init__(self):
self.my_num = self.ctr
self.ctr += 1
d1 = Doh()
d2 = Doh()
print(f"d1: {d1.my_num}")
print(f"d2: {d2.my_num}")
I run it expecting d1 and d2 to have different values for self.my_num
but they both come out 0:
d1: 0
d2: 0
So clearly I don't get how class variables work with +=. What am I doing wrong?