n = int(input())
a = []
b = []
c = []
for i in range(n):
A, B, C = map(int, input().split())
a.append(A)
b.append(B)
c.append(C)
1.普通输入
##输入一行2 3
a = input().split()
print(a) ##["2","3"]
##输入两行
##5
##1 5 6
a = []
b = input()
print(b)##5
s = input().split()
print(s) ##['1','5','6']
for i in s:
a.append(i)
print(a)##[1,5,6]
2.输出以空格或其他字符隔开
##空格
print(a, end=' ')
##逗号
print(a, end=',')
##
3.循环输入
##2##两组数据
##222 555 222
##55 558 5552
a = input()##2
b = input()##222 555 222
c = input()##55 558 5552
4.输出去掉换行符
print(str.replace('\n',''))
一行输入如果输入只有一个数或者一个字符串的话,直接使用input读取就可以了
s = input()
print(s)
输入一个数组的话和输入一个数类似,只不过需要使用split()分解一下
s = input()
s = [i for i in s.split()]
print(s)
两行读取要在一行读取的基础上再进行一些操作。这里举个例子,假设第一行输入数组长度,第二行输入数组,那么读入操作分两步,首先获得数组长度,然后获取数组。
while True:
s = input()
if s != "":
length = int(s)
nums = [int(i) for i in input().split()]
print(length, nums)
break
else:
break
如果每行只输入一个数或者字符串的话这种情况直接使用while循环和input进行读取。
while True:
s = input()
if s != "":
print(s)
else:
break
有的时候题目要求每行内容输入不同,举个例子,第一行输入操作个数,从第二行还是输入n个数组。
data = []
length = int(input())
n = 0
while n < length:
s = input()
if s != "":
temp = [i for i in s.split()]
data.append(temp)
n = n + 1
else:
break
print(data)
转自:
https://blog.csdn.net/yushu4772/article/details/83005308
https://blog.csdn.net/sinat_35821976/article/details/89509757#1.%20一行输入