How to Append List Elements in Python

In this article, you will learn how to append list elements in Python. Let’s say you have 2 lists of food. Append List Elements in…

The post How to Append List Elements in Python appeared first on CodeSource.io.


This content originally appeared on CodeSource.io and was authored by Ariessa Norramli

In this article, you will learn how to append list elements in Python.

Let’s say you have 2 lists of food.

# A list named 'food' with value ["Pizza", "Burger"]
food = ["Pizza", "Burger"]

# A list named 'moreFood' with value ["Waffle", "Fried Chicken"]
moreFood = ["Waffle", "Fried Chicken"]

Append List Elements in Python

In order to append list elements, you can use the list.extend() keyword.

# A list named 'food' with value ["Pizza", "Burger"]
food = ["Pizza", "Burger"]

# A list named 'moreFood' with value ["Waffle", "Fried Chicken"]
moreFood = ["Waffle", "Fried Chicken"]

# Append list named 'moreFood' at the end of list named 'food'
food.extend(moreFood)

# Display list named 'food'
print(food)
# ['Pizza', 'Burger', 'Waffle', 'Fried Chicken']

Note: The list.extend() keyword functions by appending the elements of supplied iterable at the end of list.

The post How to Append List Elements in Python appeared first on CodeSource.io.


This content originally appeared on CodeSource.io and was authored by Ariessa Norramli


Print Share Comment Cite Upload Translate Updates
APA

Ariessa Norramli | Sciencx (2021-02-25T11:03:10+00:00) How to Append List Elements in Python. Retrieved from https://www.scien.cx/2021/02/25/how-to-append-list-elements-in-python/

MLA
" » How to Append List Elements in Python." Ariessa Norramli | Sciencx - Thursday February 25, 2021, https://www.scien.cx/2021/02/25/how-to-append-list-elements-in-python/
HARVARD
Ariessa Norramli | Sciencx Thursday February 25, 2021 » How to Append List Elements in Python., viewed ,<https://www.scien.cx/2021/02/25/how-to-append-list-elements-in-python/>
VANCOUVER
Ariessa Norramli | Sciencx - » How to Append List Elements in Python. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/02/25/how-to-append-list-elements-in-python/
CHICAGO
" » How to Append List Elements in Python." Ariessa Norramli | Sciencx - Accessed . https://www.scien.cx/2021/02/25/how-to-append-list-elements-in-python/
IEEE
" » How to Append List Elements in Python." Ariessa Norramli | Sciencx [Online]. Available: https://www.scien.cx/2021/02/25/how-to-append-list-elements-in-python/. [Accessed: ]
rf:citation
» How to Append List Elements in Python | Ariessa Norramli | Sciencx | https://www.scien.cx/2021/02/25/how-to-append-list-elements-in-python/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.