i wrote 2 simple codes in python that should make the same work, but it doesnt. if you can tell me why is this, and also explain me more about the "everything is an object in python". thanks :)
def f(p=[]):
print p
f.a += 1
print id(p)
if(f.a == 1):
p = p + [4]
else:
p = p + [5]
return p
f.a = 0
f()
f()
f()
answer:
[] 40564496 [] 40564496 [] 40564496
def f(p=[]):
print p
f.a += 1
print id(p)
if(f.a == 1):
p += [4]
else:
p +=[5]
return p
#print f()
#print f()
f.a = 0
f()
f()
f()
answer:
[] 40892176 [4] 40892176 [4, 5] 40892176
like you see - the first code every time does a new list, and the second add to the last used one...