#!/usr/bin/env python#-*-coding:utf-8-*-A='ABC'b=AA='def'Print(b)#This is the ABC printed here.#1. Execute a = ' abc ', the interpreter creates the string ' abc ' and variable A, and points a to ' ABC '#2. Execute B=a, the interpreter creates the variable B and points the variable B to the ABC that the variable a points to#3. Execute a = ' def ', the interpreter creates the string ' def ' and changes the direction of a to ' Def ', but B does not change:#so the final print is ABC.name={ "Z":{" Age": 20,"JX":"TN"}, "h":{" Age": 20,"JX":"TN"}, "x": 2,}name2=namename['Z'][' Age']=' A'Print('name is:', name)Print('name2 is:', name2)#Results#name is: {' Z ': {' JX ': ' tn ', ' age ': ' + '}, ' H ': {' JX ': ' tn ', ' Age ': $}}#name2 is: {' Z ': {' JX ': ' tn ', ' age ': ' + '}, ' H ': {' JX ': ' tn ', ' Age ' : ' +}}#here is the equivalent of making an alias, a soft connection, no longer occupy a piece of memory. This way, whether you change the name or the name2 is a piece of data for the operation. #With the first example there is a difference, for strings and numbers some data types of processing, will create a new copy of the data in memory, but the list, tuples, dictionaries, will not be processed like this. #Copy the first layername3=name.copy () name['x']='after the original dictionary has changed'name['h'][' Age']=' Age'Print(name)Print(Name3)#completely separate data, occupying memory of the same size as the meta dataImportCopyname4=copy.deepcopy (name)
Python's depth copy