Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我知道怎么做的一种方法是
while 1: try: n=int(raw_input()) except: break
还有比这更短的方法吗?
比这更短的意思是只消耗更少的字符。
对于以下代码,read()调用将阻塞,直到遇到 EOF:
read()
import sys sys.stdin.read()
或者一次执行一行以消耗更少的内存:
import sys for line in iter(sys.stdin.readline, ''): pass
import sys sys.stdin.read() # Reads all input.