Python中多行输入

多行输入


import sys
strList = []
for line in sys.stdin:  #没有当接受到输入结束信号就一直遍历每一行
    tempStr = line.split()#对字符串利用空字符进行切片
    strList.extend(tempStr)#
# 多行输入
# 1.利用异常处理机制
# ctrl+c结束输入
# windows中
lines=[]
while True:
	try:
		lines.append(input())
	except:
		break
print(lines)

#利用标准输入输出
#Linux中使用ctrl+d结束输入
import sys
lines=sys.stdin.readlines()
print(lines)

#标准输入输出
#Linux中使用ctrl+d结束输入
import sys
if __name__ == '__main__':
	strlist=[]
	for line in sys.stdin:
		strt=line.split()
		strlist.extend(strt)
#增加判断
lines=[]
while True:
	try:
		strs=input()
		if strs=='':
			break
		else:
			lines.append(strs)
	except:
		break
print(lines)

#!/usr/bin/python3
#_*_ coding:utf-8 _*_
strList=[]
while True:
	strin=input()
	if strin=='':
		break
	else:
		strList.append(strin)
print(strList)

  

 
原文地址:https://www.cnblogs.com/shineriver/p/12187447.html