Home >Backend Development >Python Tutorial >What is the usage of insert in python?
Description
The insert() function is used to insert the specified object into the specified position in the list.
Syntax
insert() method syntax:
list.insert(index, obj)
Parameters
index -- object obj The index position to be inserted.
obj -- The object to be inserted into the list.
Return value
This method has no return value, but will insert the object at the specified position in the list.
Examples
The following examples show how to use the insert() function:
#!/usr/bin/python aList = [123, 'xyz', 'zara', 'abc'] aList.insert( 3, 2009) print "Final List : ", aList
The output results of the above examples are as follows:
Final List : [123, 'xyz', 'zara', 2009, 'abc']
numerouspython training videos, all on the python learning network, welcome to learn online!
The above is the detailed content of What is the usage of insert in python?. For more information, please follow other related articles on the PHP Chinese website!