Python swapping lists

后端 未结 3 745
灰色年华
灰色年华 2021-01-11 22:44

In python, when I assign a list to another, like:

a = [1,2,3]
b = a

Now b and a point to the same list. Now considering two lists,

3条回答
  •  耶瑟儿~
    2021-01-11 23:21

    Now how is it that they are swapped like any other data type and does not end up both pointing to the same list?

    Because the moment you unpack the tuple b, a into the tuple a, b you loose references to the original a and b and they get re-assigned.

提交回复
热议问题