This question already has an answer here:
- How to concatenate two lists in Python? 30 answers
In Python, the only way I can find to concatenate two lists is list.extend
, which modifies the first list. Is there any concatenation function that returns its result without modifying its arguments?
Just to let you know:
When you write
list1 + list2
, you are calling the__add__
method oflist1
, which returns a new list. in this way you can also deal withmyobject + list1
by adding the__add__
method to your personal class.