import sysfor line in sys.stdin: if line is '\n': break这种方式即可实现输入的为空字符串时输入循环结束,或者无论用不用这句话都可以用crtl+D来实现输入结束。