Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python3 List insert() Method

Python3 List insert() Method

Python3 Lists The Python3 list


Description

The insert() function inserts a specified object at a specified position in a list.

Syntax

insert() method syntax:


list.insert(index, obj)

Parameters

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'

)

print

(

'The list after insertion: '

,

list1

)

The output of the above example is:


列表插入元素后为 :  ['Google', 'Baidu', 'Runoob', 'Taobao']

Python3 Lists The Python3 list