I need to input 3 integers form stdin and outut their sum. Here's what i do:
(n,l,k) = raw_input().split()
print n + l + k
Of course, i get n,l,k string concatenation, so i change this a little:
(n,l,k) = raw_input().split()
print int(n) + int(l) + int(k)
Now it's ok. But is there any way to set data type for the variables 'on the fly', so n,l,k became int whitout explicit reassigning for further use( i think of n = int(n) ) ?
UPDATE:
What if i need to input int, string, int (tuple items are of different types) ?
THis means i can't do
(n,S,k) = [int(i) for i in raw_input().split()]
Any zip(), lambdas, accepting types?
Thanks in advance, Ilya
int(n) + l + int(k)is how you handleint,str,int.