python里面list列表中extend和append的比较

What's the difference? If you append a list to another list, you add the new list as a single extra list to the original, thus makingthe original list just one longer with an item that is itself a list. But if you extend a list with another list, you add each element of the new list onto the original. Here's an example to show you what I mean:

>>> first = [10,20,30]
>>> second = [40,50,60]
>>> first.append([70,80,90])
>>> second.extend([100,110,120])
>>> first
[
102030, [708090]]
>>> second
[
405060100110120]
>>>


相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-05-24
  • 2021-10-31
  • 2022-12-23
  • 2021-11-23
  • 2021-11-29
  • 2021-11-29
猜你喜欢
  • 2021-11-29
  • 2021-11-29
  • 2022-01-20
  • 2021-07-18
  • 2021-11-29
  • 2021-11-29
  • 2022-12-23
相关资源
相似解决方案