Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #82158

Re: Question on lambdas

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.006
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'argument': 0.05; 'subject:Question': 0.07; 'function,': 0.09; 'cc:addr:python- list': 0.11; 'def': 0.12; 'argument,': 0.16; 'example?': 0.16; 'expression,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'lambda': 0.16; 'lambda:': 0.16; 'ought': 0.16; 'simple.': 0.16; 'wrote:': 0.18; 'example': 0.22; '(in': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'equivalent': 0.26; 'this:': 0.26; 'second': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'am,': 0.29; 'dec': 0.30; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; 'getting': 0.31; 'quite': 0.32; 'trouble': 0.34; 'case,': 0.35; 'received:google.com': 0.35; 'words,': 0.36; 'two': 0.37; 'though,': 0.39; 'sure': 0.39; 'skip:u 10': 0.60; 'above,': 0.60; 'simply': 0.61; 'first': 0.61; '10:43': 0.84; 'functions:': 0.84; 'to:none': 0.92
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=voDe506UPlZgFrBO/GGmkWoQs5jknDDQgDjalxie/H4=; b=Pwx6aw3cdpTrEBjZ9wc/KjF/QMtAo4ZQ1up0mniT3d2vSEj1J2VmJPvIjQ0F0E7yPO nZCAKSixrr/1j28+9Q9anMej1i7chfphP32Gand4+PlqnBTrYXOeMjUyWq5YcTgcxYrg QOx6pcEaVeWVeOa75PETKLCKMYR2sOwPNYq3j+hIYCUXYHmcms425PTFX5x64SejoUmT OPapSM2/fKmP2yawR8N1sn8YCnuUgzBjbj/FGJZFjAE7zuIz5rudGwxmu3aSQXHlNGrZ 3k4Q+gqNnqsgI9Vxmd3Z2RPWlydZ+lV9DKTvIQPDJKDWy8U/0fL4vKo64K4yj+k9pljL /mTA==
MIME-Version 1.0
X-Received by 10.42.94.14 with SMTP id z14mr6579icm.59.1418082864393; Mon, 08 Dec 2014 15:54:24 -0800 (PST)
In-Reply-To <m65d2m$3pe$1@ger.gmane.org>
References <m65d2m$3pe$1@ger.gmane.org>
Date Tue, 9 Dec 2014 10:54:24 +1100
Subject Re: Question on lambdas
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.16744.1418082867.18130.python-list@python.org> (permalink)
Lines 37
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1418082867 news.xs4all.nl 2829 [2001:888:2000:d::a6]:57655
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:82158

Show key headers only | View raw


On Tue, Dec 9, 2014 at 10:43 AM, memilanuk <memilanuk@gmail.com> wrote:
> What I'm having trouble finding a concrete answer to is the difference
> between:
>
> lambda: some_func
>
> lambda e: some_func

These two are quite simple. (In each case, it's an expression, not a
function, for what it's worth.) They're (roughly) equivalent to these
functions:

def anonymous():
    return some_func
def anonymous(e):
    return some_func

In other words, the second one takes an argument, the first doesn't.

> lambda e=e: some_func

I'm not sure what this one ought to be; do you have an example? If the
"e=" part comes before the "lambda", though, then it's simply a named
argument getting a lambda function bound to it. In your example above,
this:

Radiobutton(... command=lambda: update_label2('A', 100))

is equivalent to this:

def anonymous():
    return update_label2('A', 100)
RadioButton(... command=anonymous)

It's that simple.

ChrisA

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Question on lambdas Chris Angelico <rosuav@gmail.com> - 2014-12-09 10:54 +1100

csiph-web