python - Explain the code function in call by object -


how y equal x call object no function call how work how y value change

y = [1, 2, 3] x = y x[:] = [-1]*3 print y [-1, -1, -1] 

please explain happen in x , y , call object

y = [1, 2, 3] x = y 

x , y both point same list.

x[:] = [-1]*3 

that list modified, way of assignment whole-object-slice (see here).

print y # [-1, -1, -1] 

the modified list printed console.

and way: there no "call object". assignment slice (which, noted in link, modifies object).


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -