Am 14.08.2016 um 13:06 schrieb ast:
[snip]
Thanks. The use of id() is very helpful in clarifying
what acutally happens in the present case.
M. K. Shen
--
https://mail.python.org/mailman/listinfo/python-list
"Mok-Kong Shen" a écrit dans le message de
news:noo1v6$r39$1...@news.albasani.net...
Am 13.08.2016 um 03:08 schrieb Steven D'Aprano:
On Sat, 13 Aug 2016 06:44 am, Mok-Kong Shen wrote:
list2 = [1,2,3]
list1 += [4,5,6]
print(list1, list2)
[1, 2, 3, 4, 5, 6] [1, 2, 3]
Does that help?
I do
Am 13.08.2016 um 03:08 schrieb Steven D'Aprano:
On Sat, 13 Aug 2016 06:44 am, Mok-Kong Shen wrote:
list2 = [1,2,3]
list1 += [4,5,6]
print(list1, list2)
[1, 2, 3, 4, 5, 6] [1, 2, 3]
Does that help?
I don't yet understand why in my 2nd example list2 came out as
[1, 2, 3] outside.
Because y
On Sat, 13 Aug 2016 06:44 am, Mok-Kong Shen wrote:
> list2 = [1,2,3]
> list1 += [4,5,6]
> print(list1, list2)
>> [1, 2, 3, 4, 5, 6] [1, 2, 3]
>>
>>
>> Does that help?
>
> I don't yet understand why in my 2nd example list2 came out as
> [1, 2, 3] outside.
Because you assign list2 = [1
Am 11.08.2016 um 23:49 schrieb Gary Herron:
On 08/11/2016 03:06 PM, Mok-Kong Shen wrote:
def test(list1,list2):
list1+=[4,5,6]
list2=list2+[4,5,6]
print("inside ",list1,list2)
return
[snip]
# With
list1=[1,2,3]
list2=[1,2,3]
test(list1,list2)
print("outside",list1,list2)
# I got th
Note that your subject line is wrong. You are not doing list concatenation.
Unfortunately, for technical and optimization reasons, the += assignment
operator for lists is in-place, which means that it is NOT the same as
ordinary list concatenation + operator. It is equivalent to calling the
list.e
On 08/11/2016 03:06 PM, Mok-Kong Shen wrote:
def test(list1,list2):
list1+=[4,5,6]
list2=list2+[4,5,6]
print("inside ",list1,list2)
return
# With
list1=list2=[1,2,3]
test(list1,list2)
print("outside",list1,list2)
# I got the following:
# inside [1, 2, 3, 4, 5, 6] [1, 2, 3, 4, 5, 6, 4
def test(list1,list2):
list1+=[4,5,6]
list2=list2+[4,5,6]
print("inside ",list1,list2)
return
# With
list1=list2=[1,2,3]
test(list1,list2)
print("outside",list1,list2)
# I got the following:
# inside [1, 2, 3, 4, 5, 6] [1, 2, 3, 4, 5, 6, 4, 5, 6]
# outside [1, 2, 3, 4, 5, 6] [1, 2, 3,