如何在 Python 中连接两个列表? [英] How do I concatenate two lists in Python?

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

问题描述

如何在 Python 中连接两个列表?

示例:

listone = [1, 2, 3]列表二 = [4, 5, 6]

预期结果:

<预><代码>>>>加入名单[1, 2, 3, 4, 5, 6]

解决方案

您可以使用 + 运算符将它们组合起来:

listone = [1, 2, 3]列表二 = [4, 5, 6]joinlist = listone + listtwo

输出:

<预><代码>>>>加入名单[1, 2, 3, 4, 5, 6]

How do I concatenate two lists in Python?

Example:

listone = [1, 2, 3]
listtwo = [4, 5, 6]

Expected outcome:

>>> joinedlist
[1, 2, 3, 4, 5, 6]

解决方案

You can use the + operator to combine them:

listone = [1, 2, 3]
listtwo = [4, 5, 6]

joinedlist = listone + listtwo

Output:

>>> joinedlist
[1, 2, 3, 4, 5, 6]

这篇关于如何在 Python 中连接两个列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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