A strange list concatenation result

Steven D'Aprano steve+python at pearwood.info
Fri Aug 12 21:08:36 EDT 2016


On 2016年8月13日 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, 2, 3]. What did you expect it to be?
-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /