列表append的另一种形式:切片取值赋值

已知x = [3,5,7],那么执行语句x[len(x):] = [1,2]之后,x的值为:
x = [3,5,7]
x[len(x):] = [1,2]
print(x) # [3, 5, 7, 1, 2]


已知x = [[1]]*3,那么执行语句`x[0][0]=5`之后,变量x的值为:
x = [[1]]*3
print(x) # [[1], [1], [1]]
x[0][0]=5
print(x) # [[5], [5], [5]]
 
posted @ 2019-05-03 01:04  输诚  阅读(376)  评论(0编辑  收藏  举报