代码之家  ›  专栏  ›  技术社区  ›  Rhys

字典链接[副本]

  •  0
  • Rhys  · 技术社区  · 6 年前

    我对字典不熟悉,发现下面的内容很混乱。

    resume = [{'name': 'New', 'value1': 'dfgdf'}, {'name': 'garry', 'value1': 'hhhhhh'}]
    current = resume[0]
    current['name'] = '24/7 link was not requested...'
    print(resume)
    

    退货:

    [{'name': '24/7 link was not requested...', 'value1': 'dfgdf'}, {'name': 'garry', 'value1': 'hhhhhh'}]
    

    为什么会发生这种情况 resume current ? ...... 我怎样才能改变这个 current['name'] 不恢复 .

    1 回复  |  直到 6 年前
        1
  •  3
  •   Sebiancoder    6 年前

    尝试改变

    current = resume[0]
    

    current = resume[0].copy()
    

    这将创建一个新的dictionary对象。