Latest web development tutorials

Python List insert () method

Python list Python 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/python

aList = [123, 'xyz', 'zara', 'abc']

aList.insert( 3, 2009)

print "Final List : ", aList

Examples of the above output results are as follows:

Final List : [123, 'xyz', 'zara', 2009, 'abc']

Python list Python list