Pythonリストinsert()メソッド
例
fruit
リストの2番目の要素として値「orange」を挿入します。
fruits = ['apple', 'banana', 'cherry']
fruits.insert(1, "orange")
定義と使用法
このinsert()
メソッドは、指定された値を指定された位置に挿入します。
構文
list.insert(pos, elmnt)
パラメータ値
Parameter | Description |
---|---|
pos | Required. A number specifying in which position to insert the value |
elmnt | Required. An element of any type (string, number, object etc.) |