如何在Python中采用多个多行输入变量?

dep*_*pfx 1 python input raw-input python-2.7 python-3.x

是否可以将多个换行符输入到多个变量中int并一次声明它们?

为了进一步解释我要完成的工作,我知道这是我们如何使用map进行空格分隔的输入:

>>> a, b = map(int, input().split())
3 5
>>> a
3
>>> b
5
Run Code Online (Sandbox Code Playgroud)

有换行符吗?就像是:

a, b = map(int, input().split("\n"))

改写:我试图一次从多行中获取多个整数输入。

Ami*_*ani 5

正如其他人所说的;我认为您无法使用input()

但是您可以这样做:

import sys
numbers = [int(x) for x in sys.stdin.read().split()]
Run Code Online (Sandbox Code Playgroud)

请记住,您可以按来完成输入Ctrl+D,然后您将看到一个数字列表,可以像这样打印它们(只是检查它是否起作用):

for num in numbers:
    print(num)
Run Code Online (Sandbox Code Playgroud)

编辑:例如,您可以使用这样的条目(每行一个数字):

1
543
9583
0
3
Run Code Online (Sandbox Code Playgroud)

结果将是: numbers = [1, 543, 9583, 0, 3]

或者,您可以使用像这样的条目:

1
53          3
3 4 3 
      54
2
Run Code Online (Sandbox Code Playgroud)

结果将是: numbers = [1, 53, 3, 4, 3, 54, 2]