Professional Documents
Culture Documents
DataCamp Team
June 24th, 2020
PYTHON +1
You can add elements to a list using the append method. The append() method adds a
single element towards the end of a list.
For example, let’s extend the string by adding “April” to the list with the method
append() . Using append() will increase the length of the list by 1.
https://www.datacamp.com/community/tutorials/python-list-methods 1/4
1/1/2021 (Tutorial) Python .append() and .extend() Methods - DataCamp
x = [1, 2, 3]
x.append(4)
x
[1, 2, 3, 4]
The .extend() method increases the length of the list by the number of elements that
are provided to the method, so if you want to add multiple elements to the list, you can
use this method.
x = [1, 2, 3]
x.extend([4, 5])
x
[1, 2, 3, 4, 5]
We can then add two additional elements to the list names using extend() and the
more_elements list.
https://www.datacamp.com/community/tutorials/python-list-methods 2/4
1/1/2021 (Tutorial) Python .append() and .extend() Methods - DataCamp
To learn more about list methods and functions, please see this video from our course
Introduction to Python for Finance.
This content is taken from DataCamp’s Introduction to Python for Finance course by
Adina Howe.
0
https://www.datacamp.com/community/tutorials/python-list-methods 3/4
1/1/2021 (Tutorial) Python .append() and .extend() Methods - DataCamp
Subscribe to RSS
https://www.datacamp.com/community/tutorials/python-list-methods 4/4