November 2001
Beginner
320 pages
5h 53m
English
One of the problems with Python using references to data all of the time is that it can play havoc with data structures which are using references, rather than copies of data from other variables. For example, the following fragment creates two variables, alist and blist:
>>> alist = [25,50,75,100] >>> blist = alist
The blist variable is a reference to the same array object as alist, which means changing a value in the variable alist modifies the same list to which blist points, such that:
>>> alist[3] = 2000 >>> alist [25, 50, 75, 2000] >>> blist [25, 50, 75, 2000] >>>
We get the same value – both alist and blist point to the same array, so modifying values in one modifies the values we get back from the other.
To make ...