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.
1.4m articles
1.4m replys
5 comments
57.0k users