Languages
[Edit]
EN

Python - extend list

0 points
Created by:
ParaEagle
724

In this article, we would like to show you how to extend list in Python.

Quick solution:

list1 = ['A', 'B']
list2 = ['C', 'D']

list1.extend(list2)

print(list1)  # ['A', 'B', 'C', 'D']

 

Practical example

In this example, we use extend() method to extend the list1 by appending elements from the list2 at the end of list1.

list1 = ['A', 'B']
list2 = ['C', 'D']

list1.extend(list2)

print(list1)  # ['A', 'B', 'C', 'D']

Output:

['A', 'B', 'C', 'D']

Alternative titles

  1. Python - append elements from one list to another
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Python - list (popular problems)

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join