LoginSignup
1
0

More than 5 years have passed since last update.

pythonの一列に複数の値が入力され、それらを取得する方法

Last updated at Posted at 2018-03-12

一列に

123 789

という値が入力され、

これを

x=123
y=789

で取得したいとき

x, y = input().split()
#x=123 y=789

で簡単に取得可能!!

僕的には新発見でした(笑)

どのような原理なのかは、コメント欄のshiracamusさんのコメントをご参照下さい!

LouiS0616さんより、整数ならばキャストした方が使いやすいというご意見を!
こちらに載せさせて頂きます!

x, y = map(int, input().split())
123 456
x, type(x)
(123, #class 'int')
y, type(y)
(456, #class 'int')

引用
https://teratail.com/questions/66859

1
0
4

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
0