Python List Append


Python List Append is one of the most used Python List Methods. With this Python List Append method, we can add a new member to the end of the lists. Let’s give some example to learn this python function better.


Below, we will use append() method to add new string members at the end of the string.


characters = ["Frodo", "Aragorn", "Arwen", "Gandalf"]


The output of this Python List Append code will be like below:


['Frodo', 'Aragorn', 'Arwen', 'Gandalf', 'Legolas', 'Gimli', 'Boromir']


You can learn also How to Sort Python Lists


You can also watch this lesson on Youtube!

We can do the same thing that we do above, with plus (+) operator like blow. Here, we will use two different string lists and we will combine these string lists in one string.


characters1 = ["Aragorn", "Arwen", "Gandalf"]
characters2 = ["Legolas", "Gimli", "Boromir"]

The output of this python code will be like below:

['Aragorn', 'Arwen', 'Gandalf', 'Legolas', 'Gimli', 'Boromir']




We can use Python List Append code for number lists also. Below, we will add 100 to the end of number list.


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


The output of this python command will be like below:


[1, 2, 3, 4, 5, 100]



If we use Python List Append code with two lists, the second list is added to the previous list like below:


characters1 = ["Aragorn", "Arwen", "Gandalf"]
characters2 = ["Legolas", "Gimli", "Boromir"]


['Aragorn', 'Arwen', 'Gandalf', ['Legolas', 'Gimli', 'Boromir']]




If you would like to extend the list, then you should use another function of python. Python list extend function an do this job. Let’s give an example for Python list extend command. Here, we will use extend () function with the new added list as parameter.


characters1 = ["Aragorn", "Arwen", "Gandalf"]
characters2 = ["Legolas", "Gimli", "Boromir"]


The output of this python code will be like below:


['Aragorn', 'Arwen', 'Gandalf', 'Legolas', 'Gimli', 'Boromir']




As you can see above, the new list has created as we use plus (+) sign.


In this lesson, we have learned how to use Python List Append code. We have done different examples on append function of python. You can increase your experience on this python method with more examples. You can also use this method with your different python codes.

Back to: Python Programming Course > Python Lists

Leave a Reply

Your email address will not be published. Required fields are marked *

IPCisco is the Winner of 2019 “Best Certification Study Journey” Category! We are also Finalist of 2020 & 2021 in Cisco IT Blog Awards!


Python Programming Course

IPCisco on Social Media!