Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #85212 > unrolled thread
| Started by | "ast" <nomail@invalid.com> |
|---|---|
| First post | 2015-02-04 15:08 +0100 |
| Last post | 2015-02-05 09:28 +0100 |
| Articles | 4 — 3 participants |
Back to article view | Back to comp.lang.python
meaning of: line, = "ast" <nomail@invalid.com> - 2015-02-04 15:08 +0100
Re: meaning of: line, = leo kirotawa <kirotawa@gmail.com> - 2015-02-04 12:22 -0200
Re: meaning of: line, = Chris Angelico <rosuav@gmail.com> - 2015-02-05 01:24 +1100
Re: meaning of: line, = "ast" <nomail@invalid.com> - 2015-02-05 09:28 +0100
| From | "ast" <nomail@invalid.com> |
|---|---|
| Date | 2015-02-04 15:08 +0100 |
| Subject | meaning of: line, = |
| Message-ID | <54d227ef$0$3292$426a74cc@news.free.fr> |
hello 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 thanks
[toc] | [next] | [standalone]
| From | leo kirotawa <kirotawa@gmail.com> |
|---|---|
| Date | 2015-02-04 12:22 -0200 |
| Subject | Re: meaning of: line, = |
| Message-ID | <mailman.18461.1423059773.18130.python-list@python.org> |
| In reply to | #85212 |
You'll find some explanation here: http://stackoverflow.com/questions/1708292/meaning-of-using-commas-and-underscores-with-python-assignment-operator On Wed, Feb 4, 2015 at 12:08 PM, ast <nomail@invalid.com> wrote: > hello > > 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 > > thanks > -- > https://mail.python.org/mailman/listinfo/python-list -- ---------------------------------------------- Leônidas S. Barbosa (Kirotawa) blog: corecode.wordpress.com
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2015-02-05 01:24 +1100 |
| Subject | Re: meaning of: line, = |
| Message-ID | <mailman.18462.1423059895.18130.python-list@python.org> |
| In reply to | #85212 |
On Thu, Feb 5, 2015 at 1:08 AM, ast <nomail@invalid.com> 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.
ChrisA
[toc] | [prev] | [next] | [standalone]
| From | "ast" <nomail@invalid.com> |
|---|---|
| Date | 2015-02-05 09:28 +0100 |
| Message-ID | <54d329b6$0$3020$426a34cc@news.free.fr> |
| In reply to | #85212 |
"ast" <nomail@invalid.com> a écrit dans le message de news:54d227ef$0$3292$426a74cc@news.free.fr... thanks for the answers
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web