hello

Consider following code:

A=7
B=7
A is B
True

I understand that there is a single object 7 somewhere in memory and
both variables A and B point toward this object 7

now do the same with a list:

l1 = [1, 2]
l2 = [1, 2]
l1 is l2
False

It seems this time that there are 2 distincts objects [1, 2] in memory. l1 
points
toward the first one and l2 points toward the second one.

if I change one, the second remains unchanged

l1.append(3)
l1
[1, 2, 3]
l2
[1, 2]

I dont really understand why the behavior is different. Both integer 7 and list [1, 2] are objects. Why is it
different ?

thanks








--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to