Python: Confused with list.remove

后端 未结 3 1137
野趣味
野趣味 2021-01-11 18:27

I\'m very new to Python, so sorry for the probably simple question. (Although, I spent now 2 hours to find an answer)

I simplified my code to illustrate the problem

3条回答
  •  离开以前
    2021-01-11 19:05

    Python has "things" and "names for things". When you write

    side = [5]
    

    you make a new thing [5], and give it the name side. When you then write

    eva = side
    

    you make a new name for side. Assignments are just giving names to things! There's still only one thing [5], with two different names.

    If you want a new thing, you need to ask for it explicitly. Usually you would do copy.copy(thing), although in the case of lists there's special syntax thing[:].

    FYI "things" are usually called "objects"; "names" are usually called "references".

提交回复
热议问题