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.


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM