0
0

More than 3 years have passed since last update.

【Python3】paizaで標準入力からの値の受け取り方

Posted at

はじめに

pythonのお勉強がてらの自分メモです
動作環境は「paiza」でやってます。

入力値が1行に1つの場合

test.py
#文字列の場合
str = input()

#数値(int)の場合
num = int(input())

入力値が1行に2つ以上の場合

※ここでは便宜上入力値は2つ、区切り文字は半角スペースとする

test.py
#文字列の場合
strA, strB = input().split(' ')

#数値(int)の場合
num1, num2 = map(int, input().split(' '))

入力値が1行に複数ある場合 ⇒ listで取得

※ここでは便宜上区切り文字は半角スペースとする

test.py
#文字列の場合
list = input().split(' ')

#数値(int)の場合1
list = list(map(int, input().split(' ')))

#数値(int)の場合2
list = [int(i) for i in input().split(' ')]
0
0
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
0