Reading Space separated input in python

2020-07-02 10:12发布

Here is the Input Specification
The program has to read t lines of inputs. Each line consist of 2 space separated values first one is the name and second is the age. An Example of Input

Mike 18
Kevin 35
Angel 56

How to read this kind of input in python? If i use raw_input(), both name and age are read in the same variable.

Update I am going to respecify the question. We already know how to read formatted input in python. Is there a way we can read formatted input in Python or not? If yes then how?

标签: python input
8条回答
淡お忘
2楼-- · 2020-07-02 11:12

For Python3:

a, b = list(map(str, input().split()))
v = int(b)
查看更多
戒情不戒烟
3楼-- · 2020-07-02 11:15
the_string = raw_input()
name, age = the_string.split()
查看更多
登录 后发表回答