Latest web development tutorials

Python3 List insert () method

Python3 list Python3 list


description

insert () function is used to specify the object into the specified position in this list.

grammar

insert () method syntax:

list.insert(index, obj)

parameter

  • index - the object obj need to insert the index.
  • obj - the list of objects to be inserted.

return value

This method does not return a value, but will insert an object in the list specified location.

Examples

The following example shows the insert () method using the function:

#!/usr/bin/python3

list1 = ['Google', 'w3big', 'Taobao']
list1.insert(1, 'Baidu')
print ('列表插入元素后为 : ', list1)

Examples of the above output results are as follows:

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

Python3 list Python3 list