How can I get the concatenation of two lists in Py

2019-01-09 23:05发布

This question already has an answer here:

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?

7条回答
Fickle 薄情
2楼-- · 2019-01-09 23:50

Just to let you know:

When you write list1 + list2, you are calling the __add__ method of list1, which returns a new list. in this way you can also deal with myobject + list1 by adding the __add__ method to your personal class.

查看更多
登录 后发表回答