Hope you are doing well

Negative indexing is bit different in behaviour. -1 will insert the element at 2nd position from right hand side.

If you want to insert element at last index, you can use:

a.insert(len(a),100)

Kindly check below example for positive and negative indexing.

import os

a = [1,2,3,4]
print ("elements before positive index ", a)

a.insert(0,100)

print ("elements after positive indexing " ,a)

a.insert(-1,3000)

print ("elements after negative indexing ",a)

a.insert(len(a),'sumit')

print ("inserting element at last position",a)




Hope this resolves your query

In case of any further issue,feel free to revert.

Kindly give your valuable feedback by clicking on any one of the smiley's below.




Regards
Sumit Anand
edureka! Solution Team
Website - www.edureka.co
Edureka claims 1st position at Deloitte's Technology Fast 50 India 2014

222576