python - 一行python中的多个输入
问题描述
如何在 Python 中的一行中获取多个输入?
这就是我想要的:
蟒蛇输入:
Enter name and age respectively: Subha 18
输出:
Your Name Is Subha and Your age is 18 years
这是我尝试过的:
inp = input()
x = inp.split()
print x[0] # Won't work
print x[1]
错误是(控制台):
SyntaxError: unexpected EOF while parsing
Traceback (most recent call last):
File "source_file.py", line 3, in <module>
inp = input()
File "<string>", line 1
11 22
^
解决方案
使用raw_input
:
inp = raw_input()
x = inp.split()
print x[0]
print x[1]