Skip to content

Python insert list into list at index | Example code

  • by

Use the Python insert() method to insert a list into the list at the index. In this method Insert an item at the specified index.

Set the index for the first parameter and the item to be inserted for the second parameter.

insert(index_value, list2)

Python example insert a list into a list at index

A simple example code inserts a list at the specified index (position). Let’s insert a list of index position 1.

list1 = [1, 2, 3]
list2 = ["A", "B", "C"]

list1.insert(1, list2)

print(list1)

Output:

Python insert list into list at index

Note: The index at the beginning is 0 . For negative values, -1 means one before the end.

Do comment if you have any doubts or suggestions on this Python list tutorial.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading