如:输入两个整数a和b,用中间的空格分隔。
答案 0 :(得分:3)
>>> s = raw_input('Input two integer a and b,separated by a space: ')
Input two integer a and b,separated by a space: 5 9
>>> [int(n) for n in s.split()]
[5, 9]
答案 1 :(得分:3)
使用str.split()
在空格处拆分字符串,然后您可以使用map
或list comprehension
将数字转换为整数:
>>> n1,n2 = map(int,raw_input().split())
100 20
>>> n1
100
>>> n2
20
>>> n1,n2 = [int(x) for x in raw_input().split()]
123 43
>>> n1
123
>>> n2
43