sys.stdin.readline( )会将标准输入全部获取,包括末尾的'\n',
input()会把‘\n’忽略
sys.stdin.readline( ).strip() 去掉末尾的换行符,
import sys a=sys.stdin.readline().strip() b=input() print(a, type(a)) print(b, type(b)) # 678 <class 'str'> # 678 <class 'str'> for line in sys.stdin: a, b = map(int, line.strip().split()) print(a + b) for line in sys.stdin: a, b = map(int, line.strip().split()) print(a + b) try: while 1: print('输入一个数: ') n = int(sys.stdin.readline().strip('\n')) print('输入多个数,空格分开:(什么都不输退出) ') # 若是多输入,strip()默认是以空格分割,返回一个包含多个字符串的list sn = sys.stdin.readline().strip() if sn == '': break sn = list(map(int,sn.split())) # 将列表元素转化成int类型 print('一个数:', n) print('多个数:', sn) except Exception as e: print("出错咧:", e)
标签:int,stdin,sys,strip,print,input,readline From: https://www.cnblogs.com/sangern/p/17463133.html