Python List insert() 方法
示例
將值 "orange" 插入到 fruit
列表的第二個位置
fruits = ['apple', 'banana', 'cherry']
fruits.insert(1, "orange")
自己動手試一試 »
定義和用法
insert() 方法在指定位置插入指定的值。
語法
list.insert(pos, elmnt)
引數值
引數 | 描述 |
---|---|
pos | 必需。指定要插入值的數字位置 |
elmnt | 必需。任何型別的元素(字串、數字、物件等) |