如何在不修改任何一个的情况下在Python中获得两个列表的串联? [英] How can I get the concatenation of two lists in Python without modifying either one?

查看:98
本文介绍了如何在不修改任何一个的情况下在Python中获得两个列表的串联?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Python中,我只能找到连接两个列表的唯一方法是list.extend,它修改了第一个列表.是否有任何串联函数返回其结果而不修改其参数?

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?

推荐答案

是:list1 + list2.这给出了一个新列表,该列表是list1list2的串联.

Yes: list1 + list2. This gives a new list that is the concatenation of list1 and list2.

这篇关于如何在不修改任何一个的情况下在Python中获得两个列表的串联?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆