Easy Tutorial
❮ Python Tutorial Python Os Utime ❯

Python3 List insert() Method

Python3 List


Description

The insert() function is used to insert a specified object into a specified position in the list.

Syntax

Syntax of the insert() method:

list.insert(index, obj)

Parameters

Return Value

This method does not return any value but inserts the object at the specified position in the list.

Example

The following example demonstrates the use of the insert() function:

#!/usr/bin/python3

list1 = ['Google', 'tutorialpro', 'Taobao']
list1.insert(1, 'Baidu')
print('The list after inserting an element is: ', list1)

The output of the above example is as follows:

The list after inserting an element is:  ['Google', 'Baidu', 'tutorialpro', 'Taobao']

Python3 List

❮ Python Tutorial Python Os Utime ❯