In this tutorial, you will learn about the Python list insert() method. The list insert function is a built-in list function which is used to insert the element on a specific position in the list.
Sometimes we need to insert a specific element on a specific position, Then we have the best list method insert() to perform that operation.
Headings of Contents
Python list insert() method:
In Python, the insert() method is a list built-in method that is used to add an element at the specific position or index number in the existing list.
List insert() method Syntax:
List insert() method Parameter:
List insert method take two parameters:
position:- Index number where the elements need to be inserted.
element:- this is the element to be inserted in the list
Return value from insert():
The insert() method does not return anything.
Note:- You have to remember, Index always stat with 0.
Example of list insert() method:
In the below example, we will insert different values into the list using the list insert() method.
#Insert a number to the 4th index number. numbers = [12, 14, 15, 17] numbers.insert(4, 30) print(numbers)
[12, 14, 15, 17, 30]
In this tutorial, You have learned about the python list insert() method to add the elements to list at a specific position or index number.
I hope this tutorial will help you. If you like this article please comment and share with your friend who wants to learn Python programming from scratch to advanced.
For More Information:- Click Here