You'll have to pass the new ordinal position to insert using len in this case:

In [62]:

a=[1,2,3,4]
a.insert(len(a),5)
a
Out[62]:
[1, 2, 3, 4, 5]
Answer from EdChum on Stack Overflow
๐ŸŒ
Finxter
blog.finxter.com โ€บ home โ€บ learn python blog โ€บ how to insert an element at the end of a list in python
How to Insert an Element at the End of a List in Python - Be on the Right Side of Change
September 16, 2022 - You insert the new element 'Bob' to the last position in the list with index len(lst). Note that Python uses zero-based indexing so the first position has index 0.
Top answer
1 of 3
1

When you use insert, you are inserting at the specified index position. Remember that lst[-x] is the same as lst[len(lst)-1-x]. For example, lst[-1] and lst[len(lst)-1-1] both refer to the last index position in the list. Once you know this, the behavior you are seeing with the negative index positions starts to make more sense:

nums = [1, 2, 3, 4, 5]

nums.insert(1, 'Hello')  # Insert at index position 1.
# Result: [1, 'Hello', 2, 3, 4, 5]

nums.insert(-1, 'Bye')  # Insert at index position len(nums)-1-1 = 4.
# Same as: nums.insert(4, 'Bye')
# Result: [1, 'Hello', 2, 3, 4, 'Bye', 5]

nums.insert(-2, 'Good')  # Insert at index position len(nums)-1-2 = 5.
# Same as: nums.insert(5, 'Good')
# Result: [1, 'Hello', 2, 3, 4, 'Good', 'Bye', 5]

To insert at the end of the list using insert:

nums = [1, 2, 3]
nums.insert(len(nums), 'Hello')
# Result: [1, 2, 3, 'Hello']

As you can see, 'Hello' was inserted in index position 3 (the original len(nums)) as specified.

If all you want to do is add an element at the end of a list, you could use append instead:

nums = [1, 2, 3]
nums.append('Hello')
# Result: [1, 2, 3, 'Hello']
2 of 3
0

To insert at the end of a list, you have to use

numbers.insert(len(numbers), 'Hello')

This will output

[5, 4, 3, 2, 1, 'Hello']

The problem you faced occurs because numbers[-i] is equivalent to numbers[len(numbers) - 1 - i]. So, numbers[-1] is actually numbers[5 - 1 - 1], i.e., numbers[3], which is exactly what was happening in your program. Insertion was happening at the 3rd index.

๐ŸŒ
ItSolutionstuff
itsolutionstuff.com โ€บ post โ€บ how-to-add-element-at-the-end-of-list-in-pythonexample.html
How to Add Element at the End of List in Python? - ItSolutionstuff.com
October 30, 2023 - There are many ways to add elements at end of the list in python. i will give you two examples using append() method and insert() method to insert element at end in python list. so let's see the below examples.
๐ŸŒ
Real Python
realpython.com โ€บ python-append
Python's .append(): Add Items to Your Lists in Place โ€“ Real Python
October 21, 2023 - Pythonโ€™s .append() takes an object as an argument and adds it to the end of an existing list, right after its last element:
Find elsewhere
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-how-to-get-the-last-element-of-list
Get the Last Element of List in Python - GeeksforGeeks
July 11, 2025 - Explanation: Last element of the list l in the above example is 6. Let's explore various methods of doing it in Python: The simplest and most efficient method uses negative indexing with a[-1]. In Python, we can use -1 as an index to access ...
๐ŸŒ
Spark By {Examples}
sparkbyexamples.com โ€บ home โ€บ python โ€บ python list insert() with examples
Python List insert() with Examples - Spark By {Examples}
May 31, 2024 - If you want to insert an element at the last position of the python list, you can use the len() method to find the total number of elements in the list and use this as an index on the insert() method along with the element you wanted to insert.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ How-to-get-the-last-element-of-a-list-in-Python
How to get the last element of a list in Python?
Input list: [5, 1, 6, 8, 3] Last element of the input list using len(list)-1 as index = 3 Last element of the input list using -1 as index = 3 ยท List slicing is a frequent practice in Python, and it is the most commonly utilized way for programmers to solve efficient problems.
๐ŸŒ
Google
developers.google.com โ€บ google for education โ€บ python โ€บ python lists
Python Lists | Python Education | Google for Developers
You may have habits from other languages where you start manually iterating over a collection, where in Python you should just use for/in. You can also use for/in to work on a string. The string acts like a list of its chars, so for ch in s: print(ch) prints all the chars in a string. The range(n) function yields the numbers 0, 1, ... n-1, and range(a, b) returns a, a+1, ... b-1 -- up to but not including the last number.
๐ŸŒ
How to Use Linux
howtouselinux.com โ€บ home โ€บ 3 ways to get last element of a list in python
3 Ways to Get Last Element of a List In Python - howtouselinux
October 9, 2025 - So list[-1] gets the last element, list[-2] gets the second to last. The list[-1] is the most preferable, shortest, and Pythonic way to get the last element. To create a list in Python, use the square brackets and add the items in the list separated by commas.
๐ŸŒ
Sentry
sentry.io โ€บ sentry answers โ€บ python โ€บ get the last element of a list in python
Get the last element of a list in Python | Sentry
In Python, we can get the last element of a list using index notation. A positive index will give us a position in the list counting from the start, whereas a negative slice index will give us a position counting from the end.
๐ŸŒ
Jessica Temporal
jtemporal.com โ€บ the-last-of-a-list-in-python
The last of the list with Python | Jessica Temporal
September 11, 2023 - Use the len() size function to get the length of the list and subtract 1 to get the index of the last element in that list. And thatโ€™s ok! It works. However, Python presents a more elegant way of doing this, see:
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ python-list-insert-how-to-add-to-a-list-in-python
Python List insert() โ€“ How to Add to a List in Python
May 10, 2022 - Unlike the insert() method which allows us to specify where to insert an item, the append() method adds the item to the end of the list. The new item's value is passed in as a parameter in the append() method.
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ tutorial โ€บ datastructures.html
5. Data Structures โ€” Python 3.14.3 documentation
The list methods make it very easy to use a list as a stack, where the last element added is the first element retrieved (โ€œlast-in, first-outโ€). To add an item to the top of the stack, use append(). To retrieve an item from the top of the ...
๐ŸŒ
Python Forum
python-forum.io โ€บ thread-30657.html
Problem printing last element from a list
Hi, I'm having a problem printing the last element from a list. I'm scanning a file for lines that have words 'find-1', 'find-2', 'find-3' and so on. I thought I will append all matching lines to a list and print only the last element from the list ...
๐ŸŒ
Note.nkmk.me
note.nkmk.me โ€บ home โ€บ python
Add an Item to a List in Python: append, extend, insert | note.nkmk.me
April 17, 2025 - In Python, you can add a single item (element) to a list using append() and insert(). You can combine lists using extend(), +, +=, and slicing. ... The append() method adds a single item to the end of a list.