0
让我说我想从标准输入读取整数a,b和c(在一行中,不需要在每个数字后按回车)。在C++中,我只会这样做:在Python中阅读更多数字
cin >> a >> b >> c;
如何在Python中做到这一点?
让我说我想从标准输入读取整数a,b和c(在一行中,不需要在每个数字后按回车)。在C++中,我只会这样做:在Python中阅读更多数字
cin >> a >> b >> c;
如何在Python中做到这一点?
values = raw_input()
# 1 3 15
a, b, c = values.split()
a
将'1'
,b
将'3'
和c
将'15'
。
如果你想成为额外的短,并得到整数试试这个:
a, b, c = [int(_) for _ in raw_input().split()]
字符串
a,b,c=raw_input().split()
对于int
a,b,c=map(int,raw_input().split())
他们将字符串,而不是整数。 – FogleBird 2010-03-21 21:32:04
请注意''raw_input'是推荐用于Python 2的版本。如此之多,它现在在Python 3中拼写为'input'(并且旧的Python 2' input'已经消失)。 http://www.python.org/dev/peps/pep-3100/ – bignose 2010-03-21 22:13:24