Such as : Input two integer a and b,separated by a space in the middle.
问问题
1124 次
2 回答
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]
于 2013-05-15T05:59:38.827 回答
3
用于str.split()
在空格处拆分字符串,然后您可以使用map
or alist 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
于 2013-05-15T06:00:34.237 回答