#聊一聊字典和集合的copy #咱们以字典举例子 #=和copy的区别 a = {"name":"3ξ","data":{"age":18,"sex":"man"}} b=a print(id(a),id(b)) a["name"] = "wusen" a["data"]["age"] = 20 print(b) """ 2038916028440 2038916028440 {'name': 'wusen', 'data': {'age': 20, 'sex': 'man'}} """ #接下来咱们看一下copy a = {"name":"3ξ","data":{"age":18,"sex":"man"}} b=a.copy() print(id(a),id(b)) a["name"] = "wusen" a["data"]["age"] = 20 print(b) """ 2038915992776 2038915422872 {'name': '3ξ', 'data': {'age': 20, 'sex': 'man'}} """ #记住:=就是完完全全都一样,内外ID都一样 # copy就是复制数据,如果内部有字典和集合,那么也会复制他们的id,所以会跟着变化 #