If prompting the user doesn't matter, this is slightly shorter than eval
for 3 or more:
a,b,c=map(input,[1]*3)
a,b,c=map(input,'111')
It's also shorter even if prompting is not ok:
a,b,c=map(input,['']*3)
Sadly, xnor's idea doesn't save anything for 2 inputs as it is still longer (19 bytes). However if you have some string (or appropriate iterable) with the appropriate length already (because magic?) then it could be shorter.
xnor found an example of a magic string for 3 inputs in Python 2 only:
a,b,c=map(input,`.5`)
This also requires that the prompts not be important, though.
This trick actually helps to save bytes for large numbers of inputs by using 1eX
notation (getting x+3 inputs):
a,b,c,d,e,f=map(input,`1e3`)
Explanation:
Python's map
function performs the function it is passed on each element of the iterable that is also passed to it, and returns the list (or map object) containing the results of these calls. For the first example, the map could be decomposed to:
[input(1), input(1), input(1)]
2The third one would probably be the best if you are taking in more than two inputs. – SuperJedi224 – 2015-05-27T17:26:50.520
1I was going to say command line arguments with
a,b=sys.argv[1:2]
or whatever but then you need animport sys
(right?) – Alex A. – 2015-05-27T17:31:41.253In python3
a,b=input().split()
would be another 19 bytes solution, not an improvement though. Note that that means a and b are strings and the input is entered in one go seperated by a space. – Matty – 2015-05-27T17:34:39.883Not sure if it helps, but in some languages you could use a vector to get two numbers, rather than 2 variables. For two arbitrary variables a more complicated container may be used. – Dennis Jaheruddin – 2015-05-28T07:56:48.510
a,b=input()
in Py2 – Oliver Ni – 2016-11-23T16:35:50.110