这是输入规范:
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
如何在 Python 中读取这种输入?如果我使用 raw_input()
,姓名和年龄都会在同一个变量中读取。
最佳答案
the_string = input()
name, age = the_string.split()
在 Python 2 中,使用 raw_input
而不是 input
。
关于python - 在 Python 中读取空格分隔的输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7637957/