开发者

Read more numbers in a line in Python

开发者 https://www.devze.com 2022-12-23 12:07 出处:网络
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:

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

精彩评论

暂无评论...
验证码 换一张
取 消