入力
入力
1 2
一行複数値の入力(数固定)
コード
x, y = map(int, input().split())
print(x, y)
#1, 2
一行複数値の入力(数不定、list型)
コード
x = list(map(int, input().split()))
print(x)
#[1, 2]
複数行複数値の入力(2次元list型)
入力
1 2 3 4
5 6 7 8
9 10 11 12
コード
data_list = [ list(map(int,input().split(" "))) for i in range(3)]
print(data_list)
#[[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]
初期化
list
1次元
x = [0] * 4
print(x)
# [0, 0, 0, 0]
2次元
x = [[0] * 4 for i in range(3)]
print(x)
# [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
行列の結合
print(a1)
# [[1 1 1]
# [1 1 1]]
print(a2)
# [[2 2 2]
# [2 2 2]]
import numpy as np
print(np.concatenate([a1, a2], 0))
# [[1 1 1]
# [1 1 1]
# [2 2 2]
# [2 2 2]]
print(np.concatenate([a1, a2], 1))
# [[1 1 1 2 2 2]
# [1 1 1 2 2 2]]
出力
list
print(x)
#[1, 2, 3, 4]
print(*x)
#1 2 3 4
print(*x, sep='')
#1234