Pythonリストアイテムの追加
リストアイテムを追加する
リストの最後に項目を追加するには、append() メソッドを使用します。
例
メソッドを使用しappend()
てアイテムを追加します。
thislist = ["apple", "banana", "cherry"]
thislist.append("orange")
print(thislist)
指定されたインデックスにアイテムを追加するには、insert()メソッドを使用します。
例
2番目の位置としてアイテムを挿入します。
thislist = ["apple", "banana", "cherry"]
thislist.insert(1, "orange")
print(thislist)