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)
 
         

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM