DEV Community

Discussion on: a += b is not the same as a = a + b

Collapse
 
paddy3118 profile image
Paddy3118

a = [1, 2, 3]
b = a
b = a + [4, 5, 6]
print('a', a) # [1, 2, 3]
print('b', b) # [1, 2, 3, 4, 5, 6]

The output for your code is nor what you stated in your second code block - you swap the a and b outputs.

Collapse
 
tahmid02016 profile image
Tahmid Hossain

Ahh... My mistake...
Thanks for commenting...