Konstantin Molchanov added the comment:

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

----------
nosy: +moigagoo

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue24136>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to