[Tutor] weird lambda expression -- can someone help me understand how this works

Alan Gauld alan.gauld at btinternet.com
Sat Dec 14 12:37:54 CET 2013


On 14/12/13 10:12, Steven D'Aprano wrote:
> On Sat, Dec 14, 2013 at 09:27:17AM +0000, Alan Gauld wrote:
>> Sorry, I don't think that is precise. lambda is not the name of the
>> function.
>
> No. But <lambda> *including the angle brackets* is the name of the
> function:
>
> py> (lambda x: x).__name__
> '<lambda>'

Ah, OK. I'll buy that.
Although I'd probably have called it the __name__ rather than just name.

I must admit I'd never even thought of checking the __name__ attribute
of a lambda, I'd kind of just assumed it would be empty (or maybe 
'anonymous')!


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos



More information about the Tutor mailing list