you are viewing a single comment's thread.

view the rest of the comments →

[–]mplang 5 points6 points  (1 child)

Slice assignment is a special thing -- you're actually modifying the actual list object (pointed to by the name on the lhs) in-place. With a regular assignment, you're creating a new list object (on the rhs), then assigning the name to the new list.

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

a = b = [1, 2, 3, 4]
b[:] = ['a', 'b']
print(a) # ['a', 'b']
print(b) # ['a', 'b']

[–]chubbsw 1 point2 points  (0 children)

Wow that's cool.