On Wed, Feb 4, 2015 at 1:18 PM, Chris Angelico <ros...@gmail.com> wrote:
> On Thu, Feb 5, 2015 at 4:36 AM, Peter Otten <__pete...@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.

Nor are most people. Nor is Python, in some places -- it seems like
people forgot about it when writing some bits of the grammar.

I'd suggest not using it.

>> (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.

C pointers don't do that either. It's really just references. (C
pointers aren't any more action-at-a-distance than Python attributes.)

Anyway, it could create a new list in Python, because Python can do
whatever it wants. But it doesn't, because as you say, that wouldn't
do anything.

-- Devin
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to