>>> lines = sys.stdin.readlines() # Read until EOF (End Of 'File'), Ctrl-D
1 # Input
2 # Input
3 # Input. EOF with `Ctrl-D`.
>>> lines # Array of string input
['1\n', '2\n', '3\n']
>>> map(int, lines) # "functional programming" primitive that applies `int` to each element of the `lines` array. Same concept as a for-loop or list comprehension.
[1, 2, 3]
根据文档,^{} 读取一行。在
多行“输入”的最小示例。在
如果您不喜欢使用
^{pr2}$map
,请考虑使用列表压缩:重新发明方形车轮很容易:
相关问题 更多 >
编程相关推荐