Wednesday, 7 August 2013

python: class variables and instance variables

python: class variables and instance variables

How python recognize class and instance level variables ? are they
different ?
For example,
class abc:
i = 10
def __init__(self):
self.i = i
a = abc(30)
b = abc(40)
print a.i
print b.i
print abc.i
output
--------
30
40
10
Means, in above example when I access a.i (or b.i) and abc.i are they
referring to completely different variables?

No comments:

Post a Comment