在Python中读取更多数字

时间:2010-03-21 21:23:02

标签: python user-input

假设我想从stdin读取整数a,b和c(在一行中,不需要在每个数字后按回车)。在c ++中,我会这样做:

cin>> a>> b>> ℃;

如何在Python中执行此操作?

2 个答案:

答案 0 :(得分:3)

表示字符串

a,b,c=raw_input().split()

for int

a,b,c=map(int,raw_input().split())

答案 1 :(得分:3)

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()]