Changing static variable from instance method in Python
python
Solution
When you assign to `self.i`, you are creating a new instance variable called `i`:
>>> print id(A.i), id(a.i)
9437588 9437576
The following will change `A.i` instead of rebinding `a.i`:
A.i = A.i + 1
or, shorter:
A.i += 1
Problem
I am trying to change a static variable in python ``` >>> class A(): ... i = 0 ... def add_i(self): ... self.i = self.i + 1 ... >>> A.i 0 >>> a = A() >>> a.add_i() >>> A.i 0 >>> a.i 1 ``` When I call `a.add_i()`, why is it not incrementing the 'static' variable `i`?