Saturday, March 24, 2018

List insert() Method


List insert() Method

The insert() method inserts object obj into list at offset index.

Syntax

list.insert(index, obj)

Parameters
   · index - This is the Index where the object obj need to be inserted.
   · obj - This is the Object to be inserted into the given list.
Return Value
This method does not return any value but it inserts the given element at the given index.

Example

#!/usr/bin/python3

list1 = ['physics', 'chemistry', 'maths']
list1.insert(1, 'Biology')
print ('Final list : ', list1)

When we run the above program, it produces the following result
Final list : ['physics', 'Biology', 'chemistry', 'maths']




<<< index( )                    Go to Index                     pop( ) >>>