LoginSignup
0
1

Python標準入力受け取り方メモ

Posted at

数値と文字列を同時に受け取る

入力される数値と文字列

ピカチュウのレベル 95

一度str型で受け取ってからint型にする

text,level=map(str,input().split())
level=int(level)

文字列で入力された配列を受け取る

入力

[1,2,3,4,5]

まずリストで受け取って" [ " と" ] "を外す。その後int型に変換して新しいリストに格納する。

receive=list(map(str,input().split()))
receive=receive[1:-1] # "1,2,3,4,5"
new_list=[]
for i in range(len(receive)):
    new_list.append(int(receive[i]))

数値を同時に受け取る

変数で受け取る

入力される値

1 2

変数で受け取る

A,B=map(int,input().split())

リストで受け取る

num_list=[(map(int,input().split()]

数値を連続で受け取る

入力される値

1 2
3 4

空のリストを作ってそれぞれに格納する

N=2
A_list=[]
B_list=[]
for i in range(N):
    A,B=map(int,input().split())
0
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
0
1