Python Add List Items
Add List Items
To add an item to the end of the list, use the append() method:
Example
Using the append() method to append an item:
thislist = ["apple", "banana", "cherry"]
thislist.append("orange")
print(thislist)
Try it Yourself »
thislist.append("orange")
print(thislist)
To add an item at the specified index, use the insert() method:
Example
Insert an item as the second position:
thislist = ["apple", "banana", "cherry"]
thislist.insert(1, "orange")
print(thislist)
Try it Yourself »
thislist.insert(1, "orange")
print(thislist)
Related Pages
Python Lists Tutorial Lists Access List Items Change List Item Loop List Items List Comprehension Check If List Item Exists List Length Remove List Items Copy a List Join Two Lists