How to use list extend() method in Python

You can easily extend a list using extend() function. let’s see how to extend a list in Python with an example for better understanding.

Example: In this example, we can see how to extend a list in Python.

Python3




#creating list
shopping = ["apple", "milk", "cookies"]
more_items = ["diaper", "baby oil"]
#extending shopping list
shopping.extend(more_items)
#printing shopping list
print(shopping)


Output

['apple', 'milk', 'cookies', 'diaper', 'baby oil']

Python List extend() Method

The Python List extend() method adds items of an iterable (list, tuple, dictionary, etc) at the end of a list.

Example

Python3




cars = ["Audi","BMW","Jaguar"]
other_cars = ["Maruti", "Tata"]
cars.extend(other_cars)
print(cars)


Output

['Audi', 'BMW', 'Jaguar', 'Maruti', 'Tata']

Similar Reads

List extend() Syntax

...

What is Python List extend() method?

list_name.extend(iterable)...

How to use list extend() method in Python

List extend() function is an in-built function of Python that extends a list by adding values of an iterable (list, tuple, string, etc) at the end of that list....

More Examples on List extend()

You can easily extend a list using extend() function. let’s see how to extend a list in Python with an example for better understanding....

Python list Extend with + Operator

...

Python list extend() vs append()

Let’s see some of the different scenarios where we use list extend() method....

Contact Us