How to add an Item in List in Python?

0
46

append() method:

append() method is used to add an item to the end of the list.

Example:

myList = ["List Item 1", "List Item 2", "List Item 3"]
myList.append("List Item 4")
print(myList)

insert() method:

insert() method is used to insert a list item at a specified index.

myList = ["List Item 2", "List Item 3", "List Item 4"]
myList.insert(1, "List Item 1")
print(myList)

extend() method:

extend() method is used to append elements from another list to the current list.

myList = ["List Item 2", "List Item 3", "List Item 4"]
myList2 = ["List Item 5", "List Item 6", "List Item 7"]
myList.extend(myList2)
print(myList)