freeCodeCamp/guide/english/python/lists/list-extend-method/index.md

780 B

title
List Extend Method

List Extend Method

There are many methods for lists, you can explore all of them by typing help(list) in your python console. One of them is the extend function which, as the name says extends the list by adding all items of a list (passed as an argument) to the end.

Example Usage

cities = ["San Francisco", "Los Angeles", "New York"]
cities_in_texas = ["San Antonio", "Austin", "Dallas"]
cities.extend(cities_in_texas)
print(cities)

Output

["San Francisco", "Los Angeles", "New York", "San Antonio", "Austin", "Dallas"]

More Information:

The official documentation for extend() can be found here