Python - How to add an element at specific index in list
Published May 13, 2021In this python programming example we will cover how to add an element/object at specific index position. To add an element in list we will use list.append() method. To add element at specific index we will use insert() method.
Syntax
list.insert(index, element)
|
The above insert method requires two arguments
index: is the position, where we want to insert an element
element: is an element to be inserted in the list
Example
# Define a list with elements # print elements
|
Output:
Above example will print below output
[1, 2, 3] |
Related:
How to concatenate strings in python
Article Contributed By :
|
|
|
|
768 Views |