Syntax for one-line "nonymous" functions in "declaration style"

Rhodri James rhodri at kynesim.co.uk
Wed Mar 27 12:25:49 EDT 2019


On 27/03/2019 16:15, Bev in TX wrote:
> 
>> On Mar 27, 2019, at 10:41 AM, Antoon Pardon <antoon.pardon at vub.be> wrote:
>>
>> I don't know. Something like the following is already legal:
>>
>> f(x)[n] = x * n
>>
>> And it does something completly different.
> 
> Where would I find information on what this does in the documentation?

Nowhere in particular, it's a consequence of putting things together. 
The part that Antoon isn't mentioning is that he's presuming the 
function f(x) returns a list or something similar that we can then 
index.  You're more likely to see that sort of code written as:

a = f(x)
a[n] = x *n

which makes it look a lot less magical.

-- 
Rhodri James *-* Kynesim Ltd



More information about the Python-list mailing list