我尝试使用 input
(Py3) / raw_input()
(Py2) 来获取数字列表,但是使用代码
numbers = input()
print(len(numbers))
the input [1,2,3]
and 1 2 3
gives a result of 7
and 5
respectively – it seems to interpret the input as if it were a string .有什么直接的方法可以列出清单吗?也许我可以使用 re.findall
来提取整数,但如果可能的话,我更愿意使用更 Pythonic 的解决方案。
原文由 Underyx 发布,翻译遵循 CC BY-SA 4.0 许可协议
在 Python 3.x 中,使用它。
例子