我必须阅读python3中stdin中的未知行数。有没有办法在没有任何模块的情况下做到这一点?还有一个问题:如何表示python3中多行输入的结尾?
发布于 2019-04-03 17:27:13
试试像这样的东西
a_lst = [] # Start with empty list
while True:
a_str = input('Enter item (empty str to exit): ')
if not a_str: # Exit on empty string.
break
a_lst.append(a_str)
print(a_lst)发布于 2020-04-25 08:05:17
我们可以使用try,除了下面的方式,
while True:
try:
n = int(input())
# Perform your operations
except EOFError:
# You can denote the end of input here using a print statement
breakhttps://stackoverflow.com/questions/55500812
复制相似问题