0

In the first example a slice of a list behaves like a part of a list:

>>> l = [1, 2, 3]
>>> l[0:2] = []
>>> l
[3]

In the second example a slice of a list behaves like a copy of a list

>>> l = [1, 2, 3]
>>> k = l[0:2]
>>> k = []
>>> l[1, 2, 3]

Which general rule makes this difference? (I guess it is related to the semantics of assignment somehow. In the first example l[0:2] refers to a slice of l, but in the second example k refers only to a copy of a slice of l. In the second example does l[0:2] refer to a copy or a part?)

Dániel Sándor
  • 1,246
  • 8
  • 14

0 Answers0