Problem with assigning variables of type List

Evgeny Pedya john at ablogic.ru
Mon Aug 19 03:19:32 EDT 2002


Hello, Abhishek!
You wrote in conference comp.lang.python to <python-list at python.org> on 18
Aug 2002 21:18:47 -0700:

 AR> Hello,
 AR>       It appears that,  a = b = []
 AR> is not the same as a=[]
 AR> b=[]
 AR> because in the previous case a and b will refer to the same list eg,
 >>>> b.append(23)
 >>>> a
 AR> [23]
 AR> I am completely baffled by this. Can someone please explain?
Yes, yes, yes!
Try:
>>>a, b = [], []
>>>b.append(23)
>>>a
[]

With best regards, Evgeny Pedya.





More information about the Python-list mailing list