Describe
Insert () Inserts the specified object into the specified position in the list.
Grammar
List. Insert(index, obj)
Parameters
return value
The method does not return a value, but inserts the object at the specified position in the list.
Example 01
How to use Insert ():
Shows where the specified element is located
1 #Author: junce Liu2City = ["Hangzhou","Suzhou","Guangzhou","Suzhou","Tongzhou","Yangzhou","Zhongzhou"]3 print (city)4Print (City.index ("Suzhou") # Specifies the location where "Suzhou" is displayed. 5 6 The output results are as follows:7 1
Example 02
Insert specified position with insert
1 #Author: junce Liu2City = ["Hangzhou","Suzhou","Guangzhou","Suzhou","Tongzhou","Yangzhou","Zhongzhou"]3 print (city)4City.insert (3,"China") # Specify Index "3", insert China5 print (city)6 7 Output:8['Hangzhou','Suzhou','Guangzhou','Suzhou','Tongzhou','Yangzhou','Zhongzhou']9['Hangzhou','Suzhou','Guangzhou',' China ', 'Suzhou','Tongzhou','Yangzhou ', ' Zhongzhou ']
List Insert (Index,obj) method