[Python-Dev] Use an empty def as a lambda
anikom15 at gmail.com
Sun Sep 22 03:49:39 CEST 2013
> -----Original Message-----
> From: Python-Dev [mailto:python-dev-bounces+anikom15=gmail.com at python.org] On
> Behalf Of Ben Finney
> Sent: Saturday, September 21, 2013 12:56 PM
> To: python-dev at python.org
> Subject: Re: [Python-Dev] Use an empty def as a lambda
> Westley Martínez <anikom15 at gmail.com> writes:
> > My reasoning is that we use class to make classes, lambda to make
> > lambda functions, and def to make--well not defs--functions, which
> > doesn't really make sense to me.
> Your reasoning is flawed. There is no such thing in Python as a “lambda
> Python has functions. It doesn't matter whether you use a ‘lambda’ or
> ‘def’ statement to create it, there's no resulting difference in the
> type of the object. It is a function.
> So: you make a class with a ‘class’ statement; you make a function using
> either a ‘def’ statement or a ‘lambda’ expression. There is no third
> type of object being discussed here.
This is true. The final object the Python creates is, to my knowledge,
the same regardless of whether it uses define or lambda. But it's
irrelevant if it's the same or not, since one could argue that every-
thing is going to end up as a series of 0s and 1s. In that sense a
function is nothing more than a glorified integer. Lambda function is
just a term, like method or procedure instead function, although it is
certainly more specific in the sense that it is anonymous. In my list I
was citing general concepts, not specific Python objects.
class is obvious, lambda is obvious, def is not as obvious, though
certainly more obvious than C-style declarations. If lambda should
change I think anon or expr would be more suitable, or even func (so
long as def not become func).
More information about the Python-Dev