-3
list1 = [1,2,3,4,5]
list2 = list1.insert(-1, 100)
list2 = [1,2,3,4,100,5]

I didn't understand why the result becomes like above, but now I get it. Thanks to all of you, truly I am.

thsamajisama
  • 41
  • 1
  • 6

1 Answers1

2

the minus index counts from the right. So you're insert is inserting before the last item on the list. To add an item to the end of the list use:

list1.append(100)