meaning of: line, =
Chris Angelico
rosuav at gmail.com
Wed Feb 4 16:18:39 EST 2015
On Thu, Feb 5, 2015 at 4:36 AM, Peter Otten <__peter__ at web.de> wrote:
> Another alternative is to put a list literal on the lefthand side:
>
>>>> def f(): yield 42
>
> ...
>>>> [result] = f()
>>>> result
> 42
Huh, was not aware of that alternate syntax.
> (If you're worried: neither the list nor the tuple will be created; the
> bytecode is identical in both cases)
It can't possibly be created anyway. Python doesn't have a notion of
"assignable thing that, when assigned to, will assign to something
else" like C's pointers or C++'s references. There's nothing that you
could put into the list that would have this behaviour.
ChrisA
More information about the Python-list
mailing list