AlphaCodingSkills

Python - List insert() Method


Advertisements

The Python list insert() method is used to add an element at specified index of the list.

Syntax


list.insert(idx, elem)

Parameters

idx Required. index number at which the element need to be inserted in the list.
elem Required. value of the element which need to be inserted in the list.

Example:

In the below example, list insert() method is used to insert element called 'APR' at index = 3 in the list called MyList

month = ['JAN', 'FEB', 'MAR', 'MAY']
# add 'APR' at index=3
month.insert(3,'APR') 
print(month)

Output

['JAN', 'FEB', 'MAR', 'APR', 'MAY']

Lists Methods