Tuesday, January 27, 2015

Variable Assignment in python

The deep copy versus the shallow copy example
# note the difference between a=b and a= b[:] a = [[1,2],[3,4]] b = a[:] #shallow copy b[1] = [4,5] print a,b ############## # now watch b=a b[1] = [4,5] print a,b # see the difference? Can you explain from this how the global objects are assigned in python? #This is a good excercise.

No comments: