python - 在 Python 中读取空格分隔的输入

标签 python input

这是输入规范:

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/

相关文章:

python - 垫 python float

python - 如何在 Django-AllAuth 中自定义 ResetPasswordForm

Perl 用户输入

javascript - 如何成功地操作从用户输入中获取的数字? (HTML/JavaScript)

c++ - 简单的用户输入验证不起作用

java - 需要扫描仪输入阵列

python - Django OAuth 工具包 invalid_grant 错误

python - 使用 HttpUwsgiModule 进行 NGINX 和使用 NGINX 作为 uWSGI 的反向代理有什么区别?

python - 使用一对多关系在 Django 中创建 2 种不同的用户类型

java - 通过按钮调用时不显示用户输入。使用 Java 数组列表