I was playing around with Python classes and arrived at the following example in which two variables which appear to be static class variables have different behavior when modified.
What's going on here? My first instinct is that something tricky is going on with references.
class Foo:
a = []
n = 0
def bar(self):
self.a.append('foo')
self.n += 1
x = Foo()
print x.a, x.n ([] 0)
x.bar()
print x.a, x.n (['foo', 1])
y = Foo()
print y.a, y.n (['foo', 0])
y.bar()
print y.a, y.n (['foo', 'foo'], 1)