36,49,64,81,100]
[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
与不可变(immutable)字符串不同, 列表可变(mutable)类型,其内容可以改变:
>>> cubes...= [1,8,27,65,125] # something's wrong here
>>> cubes[3]= 64 # replace the wrong value
>>> cubes
[1..., 8, 27, 64, 125]
append()方法可以在列表结尾添加新元素
>>> cubes.append(216) # add the cube of 6
>>> cubes.append...(7 **3) # and the cube of 7
>>> cubes
[1, 8, 27, 64, 125, 216, 343]
为切片赋值可以改变列表大小,甚至清空整个列表:
>>> letters