Message246381
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 |
|
Date |
User |
Action |
Args |
2015-07-06 22:25:16 | moigagoo | set | recipients:
+ moigagoo, benjamin.peterson, docs@python, martin.panter, NeilGirdhar |
2015-07-06 22:25:16 | moigagoo | set | messageid: <1436221516.48.0.339741654145.issue24136@psf.upfronthosting.co.za> |
2015-07-06 22:25:16 | moigagoo | link | issue24136 messages |
2015-07-06 22:25:16 | moigagoo | create | |
|