Is Python list variable not passing by reference? -
i'm confused pass-by-ref , pass-by-value in python. in following code, when listb = lista
, listb should being assigned pointer (reference) list in lista variable. changes listb should reflected on lista. however, not case in test. doing wrong code? i'm running python 3.4.3
>>> lista = [1,2,3] >>> listb = lista >>> lista = [4,5,6] >>> print(lista, listb) [4, 5, 6] [1, 2, 3] >>> listb[0] ='new' >>> print(lista, listb) [4, 5, 6] ['new', 2, 3]
when lista = [4,5,6]
, reference lista
(that assigned listb
) no longer points lista
, since replaced lista
new list.
if remove line, find works expected.
Comments
Post a Comment