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 »

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 »


Copyright 1999-2023 by Refsnes Data. All Rights Reserved.