在Python中读取空格分隔的输入 [英] Reading Space separated input in python

查看:950
本文介绍了在Python中读取空格分隔的输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是输入规范
该程序必须读取t行输入.每行包含2个以空格分隔的值,第一个是名称,第二个是年龄.输入示例

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

如何在python中读取这种输入?如果我使用raw_input(),则名称和年龄都在同一个变量中读取.

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

更新 我将重新说明这个问题.我们已经知道如何在python中读取格式化的输入.有没有一种方法可以读取Python中的格式化输入?如果是,那怎么办?

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?

推荐答案

the_string = raw_input()
name, age = the_string.split()

这篇关于在Python中读取空格分隔的输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆