可以使用方括号将列表包裹起来,将其作为一个元素添加到另一个列表中,例如:

list1 = [1, 2, 3]
list2 = [4, 5, [6, 7, 8], 9]

list2.append(list1)

print(list2)

输出结果为:

[4, 5, [6, 7, 8], 9, [1, 2, 3]]

其中,list1作为一个整体被添加到了list2中。

用Python怎么将一个列表作为一个元素

原文地址: https://www.cveoy.top/t/topic/buLf 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录