[Tutor] comma in an assignment
eryksun
eryksun at gmail.com
Wed Oct 23 05:05:55 CEST 2013
On Tue, Oct 22, 2013 at 9:50 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> However, there does have to be the same number of items on both sides:
>
> py> a, b, c = "xy"
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> ValueError: need more than 2 values to unpack
3.x extends sequence unpacking to support starred expressions:
>>> a, b, *c = 'xy'
>>> a, b, c
('x', 'y', [])
>>> a, b, *c = 'xyz'
>>> a, b, c
('x', 'y', ['z'])
>>> a, b, c, *rest = 'xyzpdq'
>>> a, b, c, rest
('x', 'y', 'z', ['p', 'd', 'q'])
http://www.python.org/dev/peps/pep-3132
More information about the Tutor
mailing list