Python .append() & .extend() Methods

We can add elements to a list using the append method. The append() method adds a single element towards the end of a list.

Example Of The .append() Method

list.append() adds a single element to a list

Using List Methods To Add Data: .append() Vs. .Extend()

The .extend() method increases the length of the list by the number of elements that are provided to the method, so if we want to add multiple elements to the list, we can use this method.

Interactive Example Of The .append() & .extend() Methods

When we run the above code, it produces the following result:

We can then add two additional elements to the list names using extend() & the more_elementslist.

When we run the above code, it produces the following result:

RELATED LINKS

Data Scientist & Machine Learning Engineer