Is there a way in python to do like this:
a, b, = 1, 3, 4, 5
And then:
>>> a 1 >>> b 3
(The above code doesn't work as it will throw ValueError: too many values to unpack.)
ValueError: too many values to unpack
Just to add to Nolen's answer, in Python 3, you can also unpack the rest, like this:
>>> a, b, *rest = 1, 2, 3, 4, 5, 6, 7 >>> a 1 >>> rest [3, 4, 5, 6, 7]
Unfortunately, this does not work in Python 2 though.
2.1m questions
2.1m answers
60 comments
57.0k users