Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I take tuple as input using raw_input in python?

Tags:

python

I am trying to take input. But it's not the correct syntax.

a, b, c = (int(x) for x in raw_input().strip(' '))

My idea is to take multiple values from single line which has integers separated by space. How can I do it?

like image 596
Gopi Shankar Avatar asked Dec 24 '22 10:12

Gopi Shankar


1 Answers

You were very close. It's split not strip:

a, b, c = (int(x) for x in raw_input().split())

This will take exactly 3 integers, no more no less. If you want to take an arbitrary amount into a tuple, try this instead:

tup = tuple(int(x) for x in raw_input().split())
like image 52
wim Avatar answered Dec 26 '22 00:12

wim