python3 list append list
Posted Z上善若水
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python3 list append list相关的知识,希望对你有一定的参考价值。
when you append a list to a list, something needs to be noted:
1 a = 1 2 b = [] 3 for i in range(4): 4 a = a + b 5 b.append(a)
the result is right, but when the a is a list like a=[1,1,1,1]:
1 a = [-1,-1,-1,-1] 2 b = [] 3 for i in range(4): 4 a[i] = 1 5 b.append(a)
the result will be wrong with what we need.
Due to the append use the object, and the result will be the object‘s result.
以上是关于python3 list append list的主要内容,如果未能解决你的问题,请参考以下文章
Python3基础 list append 向尾部添加一个元素
Python3基础 list append 向尾部添加一个元素