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

Alan Gauld alan.gauld at btinternet.com
Sat Dec 14 10:27:17 CET 2013


On 14/12/13 04:19, Steven D'Aprano wrote:

> Lambda is just syntactic sugar for a function. It is exactly the same as
> a def function, except with two limitations:
>
> - there is no name, or to be precise, the name of all lambda functions
> is the same, "<lambda>";

Sorry, I don't think that is precise. lambda is not the name of the 
function. You can't use lambda to access the function(s) or treat it
like any other kind of name in Python. In fact if you try to use it as a 
name you'll likely get a syntax error.

lambda is the key word that defines the function. But its no more
the name of the function than def is.


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