+ 11
Did you know that if you make an abbreviated sum (+=) of lists does not modify the id of the variable
When doing the normal sum, a = a + [1] modifies the id of the variable and when doing the abbreviated sum, a += [1] does not modify it when changing the id of the variable, the modified list is different and will not add the list indicated after the operator to the original reference a, b = [0], [0] ra, rb = a, b a = a + [1] b += [1] print (a is ra) #output False print (b is rb) #output True https://code.sololearn.com/cXGyKj6C1U9c
3 Respostas
+ 3
thank U,for mutable object , operator + call __add__ method and create a new object ,operator += call __iadd__ method just update the original object,so b is the same with rb.
+ 2
Now I know! - Thanks
+ 1
hi