Python 新增列表項
新增列表項
要將專案新增到列表末尾,請使用 append() 方法
示例
使用 append()
方法新增專案
thislist = ["apple", "banana", "cherry"]
thislist.append("orange")
print(thislist)
自己動手試一試 »
要在指定索引處新增專案,請使用 insert() 方法
示例
在第二個位置插入專案
thislist = ["apple", "banana", "cherry"]
thislist.insert(1, "orange")
print(thislist)
自己動手試一試 »