Python List - insert() Method
The Python 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. |
Return Value
None.
Example:
In the example below, 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)
The output of the above code will be:
['JAN', 'FEB', 'MAR', 'APR', 'MAY']
❮ Python List Methods