Python List extend() Method
Adds to the end of the current list the items in another list.
Syntax
Python
Copy Code
list.extend(iterable)
Parameters
Parameter | Description |
---|---|
iterable |
Required. The iterable object used to extend the current object. This can be any iterable type such as list, set, dictionary etc |
Example
Python
Copy Code
cars = ['Ford', 'Chevrolet'] foreignCars = ['BMW', 'Mercedes'] cars.extend(foreignCars) print(cars)
Output
['Ford', 'Chevrolet', 'BMW', 'Mercedes']