Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'beginner': 0.05; 'subject:Question': 0.07; 'attributes': 0.09; 'etc).': 0.09; 'methods,': 0.09; 'objects,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; 'def': 0.12; 'jan': 0.12; 'creates': 0.14; '"def"': 0.16; '"for"': 0.16; '"lambda"': 0.16; 'callables': 0.16; 'called,': 0.16; 'constructor.': 0.16; 'expression,': 0.16; 'finney': 0.16; 'function;': 0.16; 'lambda': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'statement.': 0.16; 'sugar': 0.16; 'syntactic': 0.16; 'wrote:': 0.18; '(not': 0.18; '>>>': 0.22; 'creating': 0.23; 'header:User-Agent:1': 0.23; 'values': 0.27; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'chris': 0.29; "doesn't": 0.30; 'dec': 0.30; "i'm": 0.30; 'usually': 0.31; 'could': 0.34; 'created': 0.35; 'objects': 0.35; 'but': 0.35; 'functions.': 0.36; 'like,': 0.36; 'programming,': 0.36; 'method': 0.36; 'should': 0.36; 'ben': 0.38; 'same.': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'rather': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'even': 0.60; 'new': 0.61; 'skip:\xe2 10': 0.65; 'between': 0.67; 'believe': 0.68; 'statement,': 0.68; 'fact,': 0.69; '8bit%:43': 0.74; 'special': 0.74; 'answer:': 0.84; 'distinguish': 0.84; 'etc,': 0.84; 'received:fios.verizon.net': 0.84; 'received:108': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: Question on lambdas Date: Mon, 08 Dec 2014 21:09:41 -0500 References: <548653EC.5080107@gmx.de> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Gmane-NNTP-Posting-Host: pool-108-16-203-145.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 In-Reply-To: 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: 58 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1418091001 news.xs4all.nl 2952 [2001:888:2000:d::a6]:38833 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:82171 On 12/8/2014 8:53 PM, Chris Angelico wrote: > On Tue, Dec 9, 2014 at 12:44 PM, Christoph Becker w= rote: >> Ben Finney wrote: >> >>> It's best to remember that =E2=80=98lambda=E2=80=99 is syntactic suga= r for creating a >>> function; the things it creates are not special in any way, they are >>> normal functions, not =E2=80=9Clambdas=E2=80=9D. >> >> Could you please elaborate why =E2=80=98lambda=E2=80=99 does not creat= e =E2=80=9Clambdas=E2=80=9D. I'm >> a Python beginner (not new to programming, though), and rather confuse= d >> about your statement. > > For the same reason that "def" doesn't create "defs", and "for" > doesn't create fors (uhh... the Force?). Both "lambda" and "def" > create functions. Functions are things that can be called, and they're > created by the "def" statement, the "lambda" expression, and very VERY > occasionally, by directly calling the function constructor. You could > distinguish between "lambda functions" and "def functions" if you > like, but the distinction is almost never significant. In fact, > usually you don't even need to distinguish between functions and other > callables (types, objects with __call__ methods, bound method objects, > etc, etc, etc). To exemplify Chris's answer: Consider >>> def f1(a, b=3D'hi'): return a+b >>> f2 =3D lambda a, b=3D'hi': a+b >>> I believe the only difference between any of the attributes of f1 and f2 = is >>> f1.__name__ 'f1' >>> f2.__name__ '' >>> f1.__code__.co_name 'f1' >>> f2.__code__.co_name '' All other values of corresponding attributes of f1 and f2, and=20 f1.__code__ and f2.__code__, should be the same. For instance >>> f1.__code__.co_varnames ('a', 'b') >>> f2.__code__.co_varnames ('a', 'b') --=20 Terry Jan Reedy