LoginSignup
0
2

More than 1 year has passed since last update.

input の使い方

Last updated at Posted at 2023-02-04

pythonの基本入力の方法

・一行の文字の入力方法
s = input()
#sはstr型となる

・一行の数字の入力方法
n = int(input())
#nはint型となる

split()やmap()を利用することで複数の文字や数字を受け取ることができる
・一行で複数の文字の入力方法
入力例:aaa bbb ccc
s1,s2,s3 = input().split()
入力された文字をリストに直接入れたいとき
s_list = list(input().split())

・一行で複数の数字の入力方法
入力例:111 222 333
n1,n2,n3 = map( int, input().split())
入力された数字をリストに直接入れたいとき
n_list = list( map( int, input().split() ) )

複数行の文字の入力方法
(最初に入力回数を与えられてから入力がある場合)
入力例:
3
abc
de
fgh

n = int(input())
s_list = [input() for _ in range(n)]
print(s_list)

出力
['abc', 'de', 'fgh']

0
2
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
2