New assignmens ...

dn PythonList at DancesWithMice.info
Fri Oct 22 15:49:09 EDT 2021


With apologies for pressing Send too early...

On 23/10/2021 08.41, dn via Python-list wrote:
> On 23/10/2021 08.34, Chris Angelico wrote:
>> On Sat, Oct 23, 2021 at 6:24 AM Jon Ribbens via Python-list
>> <python-list at python.org> wrote:
>>>
>>> On 2021-10-22, Stefan Ram <ram at zedat.fu-berlin.de> wrote:
>>>> Paulo da Silva <p_d_a_s_i_l_v_a_ns at nonetnoaddress.pt> writes:
>>>>> Why doesn't this work
>>>>>      if (self.ctr:=self.ctr-1)<=0:
>>>>> while this works
>>>>>      if (ctr:=ctr-1)<=0:
>>>>
>>>>   assignment_expression ::=  [identifier ":="] expression,
>>>>   but the attribute references "self.ctr" is no identifier!
>>>
>>> This seems a surprising omission. You'd expect at least 'attributeref'
>>> and 'subscription' to be allowed, if not the whole of 'target'.
>>
>> That's not the primary use-case for assignment expressions, and they
>> were highly controversial. It is much easier to expand it afterwards
>> than to restrict it, or to have the feature rejected because people
>> are scared of some small aspect of it.
> 
> 
> ie neither can one use subscripted elements, eg list-elements, as the
> LHS of an assignment expression.

Whereas, creating a list (or tuple...) is legal because the structure's
name is an "identifier"!

if ( l := [ 1, 2, 3 ] > [ 1, 2 ] ):
    print( "True" )

-- 
Regards,
=dn


More information about the Python-list mailing list