I found one issue and not able to understand the reason of difference:
code1:
class Test:
var=2
def __init__(self):
self.var=self.var+1
p=Test()
print "p.var:",p.var
q=Test()
print "q.var:",q.var
output 1:
p.var:3
q.var:3
Why not the output is(According to concept used to explain code2)
p.var:3
q.var:4
Code2:
class Test:
var=[]
def __init__(self):
self.var.append("fool")
p=Test()
print "p.var:",p.var
q=Test()
print "q.var:",q.var
output2:
p.var: ['fool']
q.var: ['fool', 'fool']
i read the article on code2 in Stack Exchange: python class instance variables and class variables
but not able to link code1 with the following concept.Please help