Python List insert() Method
Now, we are going to discuss the insert method. As the name suggests, the insert method is going to help us insert some elements at the specified index. This method takes in two arguments, in which, the first argument is the position where we want to insert the element, and the second argument is the element that needs to be inserted at that position. Let’s have a look at a simple program, which demonstrates the insert method.
Python List Insert Method
As you can see in the above program, we have a list, that contains the names of some fruits, and then we are trying to use the insert method on the list. We are giving two arguments to the list, in which the first argument is the position, and the second argument is the element that we want to insert at the specified position. Let’s have a look at the output now –
[‘Apple’, ‘Orange’, ‘Kiwi’, ‘Guava’]
As you can see, the string ‘Orange’ has been inserted into index 1, and all the other elements are shifted to the right. This method also returns None, and it updates the current list.
So, this way, we can make use of the insert method, to insert some element at the specified position in the list. We can make use of the insert method, as and when required in our Python programs.