Message 246381 - Python tracker

Message246381

Author moigagoo
Recipients NeilGirdhar, benjamin.peterson, docs@python, martin.panter, moigagoo
Date 2015-07-06.22:25:16
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1436221516.48.0.339741654145.issue24136@psf.upfronthosting.co.za>
In-reply-to
Content
Hi!

I'd like to update the docs with the examples of the new syntax usage. This is my first contribution to the Python docs, so I'd like to ask for some assistance.

I'm going to start with adding an example to the tutorial (https://docs.python.org/3.5/tutorial/introduction.html#lists). I wanted to demonstrate the new syntax with string too (https://docs.python.org/3.5/tutorial/introduction.html#strings), but it turned out to produce somewhat unexpected results:

>>> s = 'And now'
>>> first, *rest = s
>>> # I expected it to be synonymous
>>> # to ``first, rest = s[0], s[1:]``
>>> # ``first`` is expected to be 'A',
>>> # ``rest`` is expected to be 'nd now'.
>>> # ``first`` is 'A', as expected:
>>> first
'A'
>>> # But ``rest`` is implicitly turned into a list:
>>> rest
['n', 'd', ' ', 'n', 'o', 'w', ' ', 'f', 'o', 'r', ' ', 's', 'o', 'm', 'e', 't', 'h', 'i', 'n', 'g', ' ', 'c', 'o', 'm', 'p', 'l', 'e', 't', 'e', 'l', 'y', ' ', 'd', 'i', 'f', 'f', 'e', 'r', 'e', 'n', 't']

Is this behavior intended? Why wasn't ``first`` converted into ['A'] as well? Am I just not supposed to use the new unpacking with strings?

Thanks,
Konstantin
History
Date User Action Args
2015-07-06 22:25:16moigagoosetrecipients: + moigagoo, benjamin.peterson, docs@python, martin.panter, NeilGirdhar
2015-07-06 22:25:16moigagoosetmessageid: <1436221516.48.0.339741654145.issue24136@psf.upfronthosting.co.za>
2015-07-06 22:25:16moigagoolinkissue24136 messages
2015-07-06 22:25:16moigagoocreate