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: 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: References: Date: Tue, 9 Dec 2014 10:54:24 +1100 Subject: Re: Question on lambdas From: Chris Angelico Cc: "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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On Tue, Dec 9, 2014 at 10:43 AM, memilanuk 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