Python3 List insert() Method
Description
The insert() function inserts a specified object at a specified position in a list.
Syntax
insert() method syntax:
list.insert(index, obj)
Parameters
- index -- the index position at which object obj is inserted.
- obj -- the object to insert into the list.
Return Value
This method has no return value, but inserts the object at the specified position in the list.
Example
The following example shows how to use the insert() function:
Example
#!/usr/bin/python3
list1
=
[
'Google'
,
'Runoob'
,
'Taobao'
]
list1.
insert
(
1
,
'Baidu'
)
(
'The list after insertion: '
,
list1
)
The output of the above example is:
列表插入元素后为 : ['Google', 'Baidu', 'Runoob', 'Taobao']
The Python3 list