Unexpected list behavior in Python

前端 未结 5 541
-上瘾入骨i
-上瘾入骨i 2020-12-04 03:23

I wanted to reverse a list, and I managed to do so, but in the middle of the work I noticed something strange. The following program works as expected but uncommeting line <

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-04 03:52

    list_reversed = list does not make a copy of list. It just makes list_reversed a new name pointing to the same list. You can see any number of other questions about this on this site, some list in the related questions to the right.

提交回复
热议问题