Python 添加列表项
添加列表项
要将项目添加到列表末尾,请使用 append() 方法
示例
使用 append() 方法添加项目
thislist = ["apple", "banana", "cherry"]
thislist.append("orange")
print(thislist)
自己动手试一试 »
要在指定索引处添加项目,请使用 insert() 方法
示例
在第二个位置插入项目
thislist = ["apple", "banana", "cherry"]
thislist.insert(1, "orange")
print(thislist)
自己动手试一试 »