miscellaneous topics iii [ ]= print' is now'lcopy'copyl is now[ copy[ we can see that the list code did not work as we might have expected when we changed lthe copy got changed as well as mentioned in the proper way to make copy of is copy= [:the key to understanding these examples is references references everything in python is an object this includes numbersstringsand lists when we do simple variable assignmentlike = what actually happens is python creates an integer object with the value and the variable acts as reference to that object it' not that the value is stored in memory location named xbut rather that is stored somewhere in memoryand points to that location if we come along and declare = then also points to that same memory location on the other handif we then come along and say = what happens is we create new integer object with value somewhere in memory and now points at that the still exists in memory where it was and it will stay there at least until there is nothing left pointing at itat which point its memory location will be free to use for something else all objects are treated the same way when we set ='hello'the string object hello is somewhere in memory and is reference to it when we then say copy=xwe are actually saying that copy is another reference to 'helloif we then do = +'!!!'what happens is new object 'hello!!!is created and because we assigned to its is now reference to that new object'hello!!!remember that strings are immutableso there is no changing 'hellointo something ratherpython creates new object and points the variable to it when we set =[ , , ]we create list object [ , , and referencelto it when we say copy=lwe are making another reference to the object [ , , when we do [ ]= because lists are mutablethe list [ , , is changedin placeto [ , , no new object is created the list [ , , is now goneand since copy is still pointing to the same locationit' value is [ , , on the other handif we instead use copy= [:]we are actually creating new list object somewhere else in memory so that there are two copies of [ , , in memory then when we do [ ]= we are only changing the thing that points toand copy still points to [ , , just one further note to drive the point home if we set = and then set = we are first creating an integer object and pointing to it when we then set = we are creating new integer object and pointing to it the net effect is that it seems like the "valueof is changingbut what is in fact changing is what is pointing to garbage collection internally python maintains count of how many references there are to each object when the reference count of an object drops to then the object is no longer neededand the memory it had been using becomes available again