views:

69

answers:

2

Let say i want to read the integers a, b and c from stdin (in one line, do not need to press return after each number). In c++, i would just do:

cin >> a >>b >> c;

How to do this in Python ?

+3  A: 

for string

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

for int

a,b,c=map(int,raw_input().split())
S.Mark
+3  A: 
values = raw_input()
# 1 3 15
a, b, c = values.split()

a will be '1', b will be '3' and c will be '15'.


If you want to be extra short and get ints try this:

a, b, c = [int(_) for _ in raw_input().split()]
Emil Ivanov
They'll be strings, not ints.
FogleBird
Note that `raw_input` is the recommended one for Python 2. So much so, that it is now spelled `input` in Python 3 (and the old Python 2 `input` is gone). http://www.python.org/dev/peps/pep-3100/
bignose