Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2a.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.047 X-Spam-Evidence: '*H*': 0.91; '*S*': 0.00; 'result,': 0.07; 'wednesday,': 0.07; 'line:': 0.09; 'cc:addr:python-list': 0.11; 'def': 0.12; '1:08': 0.16; 'ast': 0.16; 'cleaner': 0.16; 'comma': 0.16; 'command:': 0.16; 'expecting': 0.16; "function's": 0.16; 'iterable': 0.16; 'lambda:': 0.16; 'unpack': 0.16; 'why,': 0.16; 'wrote:': 0.18; 'slightly': 0.19; 'thu,': 0.19; 'feb': 0.22; '>>>': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'equivalent': 0.26; 'this:': 0.26; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'am,': 0.29; 'work.': 0.31; 'yields': 0.31; '-----': 0.33; 'except': 0.35; 'but': 0.35; 'there': 0.35; 'returning': 0.36; 'url:org': 0.36; 'subject:': 0.39; 'received:67.195': 0.60; 'received:98.137': 0.60; 'here:': 0.62; 're:': 0.63; 'to:addr:gmail.com': 0.65; 'dont': 0.67; 'header :Reply-To:1': 0.67; 'email addr:python.org"': 0.68; 'line,': 0.68; 'of:': 0.68; 'received:gq1.yahoo.com': 0.68; 'received:mail.gq1.yahoo.com': 0.68; 'unusual': 0.74; 'saw': 0.77; '2015': 0.84; 'compare:': 0.84; 'received:bullet.mail.gq1.yahoo.com': 0.84; 'same,': 0.91; 'thing,': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1423060916; bh=KD4oNSPyoma/hRFTcOnlq+e+3EtdC6Raztlddc3oDSc=; h=Date:From:Reply-To:To:Cc:In-Reply-To:References:Subject:From:Subject; b=pGvlwb3FdCtNG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9NV7J1cxPG3F2oWEXsT. UE9Ry02._u0Hc Date: Wed, 4 Feb 2015 14:38:31 +0000 (UTC) From: Albert-Jan Roskam To: Chris Angelico In-Reply-To: References: Subject: Re: meaning of: line, = MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Cc: "python-list@python.org" X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Albert-Jan Roskam 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: 62 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1423061056 news.xs4all.nl 2889 [2001:888:2000:d::a6]:44484 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:85216 ----- Original Message ----- > From: Chris Angelico > To: > Cc: "python-list@python.org" > Sent: Wednesday, February 4, 2015 3:24 PM > Subject: Re: meaning of: line, = > > On Thu, Feb 5, 2015 at 1:08 AM, ast wrote: >> I dont understand why there is a comma just after line in the following >> command: >> >> line, = plt.plot(x, np.sin(x), '--', linewidth=2) >> >> >> I never saw that before >> >> Found here: >> > http://matplotlib.org/examples/lines_bars_and_markers/line_demo_dash_control.html >> > > That's a slightly unusual form of unpacking. Compare: > > def get_values(): > return 5, 7, 2 > > x, y, z = get_values() > > This is like "x = 5; y = 7; z = 2", because it unpacks the > function's > return value into those three targets. > > What you have is exactly the same, except that it has only one target. > So it's expecting plt.plot() to return an iterable with exactly one > thing in it, and it'll unpack it and put that thing into line: > > def get_packaged_value(): > return [42] > > x, = get_packaged_value() > > This is equivalent to "x = 42". I don't know matplotlib, so I > don't > know what it's returning or why, but as long as it's iterable and > yields exactly one thing, this will work. I have also never seen this before, but perhaps this: >>> f = lambda: [42] >>> result, = f() >>> result 42 ... is slightly cleaner than this: >>> result = f()[0] >>> result 42