Python insert list into list at index | Example code

Use the Python insert() method to insert a list into the list at index. 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 list into a list at index

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)



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 and suggestions on this Python list tutorial.

Note: IDE: PyCharm 2021.1.3 (Community Edition)

Windows 10

Python 3.7

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

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.