1
1

More than 3 years have passed since last update.

標準入力

Posted at

3行のデータの入力

for i in range(3):
    s = input()
    print(s)

N行のデータの入力

n = int(input())

for i in range (n):
  input_line = input()
  print(input_line)

区切り文字で分割

#空白で区切る
s = input().split()
print(s[0])
print(s[1])
print(s[2])

#/で区切る
s = input().split('/')
print(s[0])
print(s[1])
print(s[2])

N個のデータの入力

n = int(input())
s = input().split()

for i in range(n):
    print(s[i])

入力例1
3
aaaaa bbbbbb cccc

出力例1
aaaaa
bbbbbb
cccc

カンマ区切りの3つのデータの入力

s = input().split(',')

for i in range(3):
    print(s[i])

入力例1
aaaaa,bbbbbb,cccc

出力例1
aaaaa
bbbbbb
cccc

複数行にわたる入力

N = int(input())

for i in range(N):
    a = input()
    print(a)

入力の配列による保持(配列作れる)

n = int(input())

A = [0]*n

for i in range(n):
    a = int(input())
    A[i] = a

print(max(A))

半角スペース区切りでの出力

n = int(input())

p = ["paiza"]*n

print(" ".join(p))

入力例2
3

出力例2
paiza paiza paiza

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1