Let say i want t开发者_开发问答o 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 ?
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()]
for string
a,b,c=raw_input().split()
for int
a,b,c=map(int,raw_input().split())
精彩评论