【发布时间】:2025-12-07 07:55:01
【问题描述】:
如何从一个输入中接收多个数字作为整数列表,然后将此列表添加到另一个列表中?为了更好地解释,这是我的最后一次尝试:
list = []
for z in range (0, int(input())):
list.append(input().split())
print(list[0])
print(list[1])
print(list)
输入:
2
1 2
5 8
我得到以下输出:
['1', '2']
['5', '8']
[['1', '2'], ['5', '8']]
现在,我正在寻找的是以某种方式将这些输入作为整数接收,因此相同输入的输出将是:
[1, 2]
[5, 8]
[[1, 2], [5, 8]]
提前感谢您抽出宝贵时间提供帮助。我试图在论坛中找到解决方案,但失败了。抱歉,如果这已经被问到了。
【问题讨论】:
-
这能回答你的问题吗? Get a list of numbers as input from the user。搜索 python 整数输入列表 BTW... 的第三个谷歌结果
-
这能回答你的问题吗? Convert all strings in a list to int
标签: python integer append extend