例如,这里的代码如下:
one = [0,1]
two = [2,3]
three = [one, two]
有可能吗?
答案 0 :(得分:0)
是的。正如学生所说,在发布之前,请务必在python交互式ide中尝试输出。话虽如此,您甚至可以:
three = one + two
答案 1 :(得分:0)
使用[one, two]
,它将在该列表中写入列表,例如[[0],[1]]
。如果您只需要一个列表,则可以像one + two
那样添加它们。
>>> one = [0,1]
>>> two = [2,3]
>>> three = [one, two]
>>> three
[[0, 1], [2, 3]]
>>>
>>> three = one + two
>>> three
[0, 1, 2, 3]
>>>
答案 2 :(得分:0)
您可以执行+
运算符:
three = one+two
或者如果版本是> python 3:
three = [*one, *two]
或者可以执行extend
:
three=one.copy()
three.extend(two)
在所有示例中:
print(three)
将输出:
[0,1,2,3]