python pointer memory reallocation -


i confused python's handling of pointers. example:

a=[3,4,5] b=a a[0]=10 print 

returns [10, 4, 5]

the above indicate b , pointers same location. issue if say:

a[0]='some other type' 

b equals ['some other type', 4, 5]

this not behavior expect python have reallocate memory @ pointer location due increase in size of type. going on here?

  1. variables in python reference memory location of object being assigned.
  2. changes made mutable object not create new object

when b = a asking b refer location of a , not actual object [3, 4, 5]

to explain further:

in [1]: = [1, 2]     in [2]: b =  # b & point same list object [1, 2]     in [3]: b[0] = 9  # list mutable original list altered & since referring same list location, changes     in [4]: print [9, 2]     in [5]: print b [9, 2] 

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -