class A:
foo = 5
a = A()
a.foo =6
By writing a.foo = 6
,
we're creating an instance attribute
foo
that hides a class attributefoo
(source)
How do we know a.foo
is the instance attribute not the class attribute? Why doesnt a
use the class attribute? How to view the hidden class attribute of instance a
(if possible, since it is only hidden, not erased)?
Even after reading several related answers on SO, this still puzzles me.
Second question:
print id(A.foo)
A.foo = 0
print id(A.foo)
Why does the id of A.foo
change? It is the same class attribute pointing to different integers.