list1 = [1,2,3,4,5]
list2 = list1.insert(-1, 100)
list2 = [1,2,3,4,100,5]
I can't understand why the result becomes like above...
list1 = [1,2,3,4,5]
list2 = list1.insert(-1, 100)
list2 = [1,2,3,4,100,5]
I can't understand why the result becomes like above...
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)