List += Tuple vs List = List + Tuple

前端 未结 1 1678
天涯浪人
天涯浪人 2020-12-06 16:23

Let\'s say I have these assignments:

points = []
point = (1, 2)

How come when I do this:

points += point

相关标签:
1条回答
  • 2020-12-06 16:43

    The difference, is that list += is equivalent to list.extend(), which takes any iterable and extends the list, it works as a tuple is an iterable. (And extends the list in-place).

    On the other hand, the second assigns a new list to points, and attempts to concatenate a list to a tuple, which isn't done as it's unclear what the expected results is (list or tuple?).

    0 讨论(0)
提交回复
热议问题