list = [1,2,3] print("list = ", list)
输出结果:
list = [1, 2, 3]
1 . list.append()
例:
# 把一个元素添加到列表的结尾 list.append(4) print("list.append(4) \n",list) # 等同于 list[len(list):]=[5] print("list[len(list):]=[5] \n",list)
输出结果:
list.append(4) [1, 2, 3, 4] list[len(list):]=[5] [1, 2, 3, 4, 5]