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


Groups > comp.lang.python > #81976

The binding operator, and what gets bound to what (was: About Modifying Globals)

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 <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.027
X-Spam-Evidence '*H*': 0.95; '*S*': 0.00; 'operator': 0.03; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'def': 0.12; 'bind': 0.16; 'finney': 0.16; 'object;': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:bound': 0.16; 'wrote:': 0.18; 'example': 0.22; 'previously': 0.22; 'header:User-Agent:1': 0.23; '(or': 0.24; 'second': 0.26; 'header:X-Complaints-To:1': 0.27; "d'aprano": 0.31; 'object.': 0.31; 'parameters.': 0.31; 'steven': 0.31; 'subject:About': 0.31; 'subject:what': 0.31; 'writes:': 0.31; 'not.': 0.33; 'subject: (': 0.35; 'operations': 0.35; 'example,': 0.37; 'so,': 0.37; 'two': 0.37; 'being': 0.38; 'ben': 0.38; 'whatever': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'first': 0.61; 'subject:The': 0.64; 'different': 0.65; 'skip:\xe2 10': 0.65; 'between': 0.67; '8bit%:46': 0.78; 'kennedy': 0.84; 'received:125': 0.84; 'subject:gets': 0.84; 'philips': 0.91
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Ben Finney <ben+python@benfinney.id.au>
Subject The binding operator, and what gets bound to what (was: About Modifying Globals)
Date Fri, 05 Dec 2014 16:36:14 +1100
References <aa74bd64-0e11-492d-ae2a-4b032a0408f9@googlegroups.com> <548113f3$0$13003$c3e8da3$5496439d@news.astraweb.com>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 8bit
X-Gmane-NNTP-Posting-Host jigong.madmonks.org
X-Public-Key-ID 0xAC128405
X-Public-Key-Fingerprint 517C F14B B2F3 98B0 CB35 4855 B8B2 4C06 AC12 8405
X-Public-Key-URL http://www.benfinney.id.au/contact/bfinney-pubkey.asc
X-Post-From Ben Finney <bignose+hates-spam@benfinney.id.au>
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)
Cancel-Lock sha1:/D9wGsEnjAdPIUf9Fhw6SvM95fs=
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.16608.1417757783.18130.python-list@python.org> (permalink)
Lines 39
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1417757783 news.xs4all.nl 2884 [2001:888:2000:d::a6]:38144
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:81976

Show key headers only | View raw


Steven D'Aprano <steve+comp.lang.python@pearwood.info> writes:

> LJ wrote:
>
> > def gt(l):
> >    a["1"] = a["1"] | set([l])
>
> The difference between this example and your second one:
>
> > def gt2(l):
> >    b=b+l
>
>
> is that the second is a "binding operation" and the first is not.

I disagree; they're both binding operations (and they both use the
binding operator ‘=’ to express this).

The difference between the two is: what reference is being bound?

* In the first example, the reference is ‘a["1"]’.

  That reference is re-bound to a different object; whatever object it
  was previously bound to is forgotten.

* In the second example, the reference is ‘b’.

  That reference is re-bound to a different object; whatever object it
  was previously bound to is forgotten.

So, both of them bind (or re-bind) a reference to an object. The only
difference between the operations is the parameters.

-- 
 \      “People always ask me, ‘Where were you when Kennedy was shot?’ |
  `\                        Well, I don't have an alibi.” —Emo Philips |
_o__)                                                                  |
Ben Finney

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


Thread

About Modifying Globals LJ <luisjosenovoa@gmail.com> - 2014-12-04 12:09 -0800
  Re: About Modifying Globals Chris Angelico <rosuav@gmail.com> - 2014-12-05 07:22 +1100
  Re: About Modifying Globals Ian Kelly <ian.g.kelly@gmail.com> - 2014-12-04 13:21 -0700
  Re: About Modifying Globals Dave Angel <davea@davea.name> - 2014-12-04 18:54 -0500
  Re: About Modifying Globals Chris Angelico <rosuav@gmail.com> - 2014-12-05 10:58 +1100
  Re: About Modifying Globals Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-12-05 13:09 +1100
    The binding operator, and what gets bound to what (was: About Modifying Globals) Ben Finney <ben+python@benfinney.id.au> - 2014-12-05 16:36 +1100
      Re: The binding operator, and what gets bound to what (was: About Modifying Globals) Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-12-05 20:53 +1100
        Re: The binding operator, and what gets bound to what (was: About Modifying Globals) Chris Angelico <rosuav@gmail.com> - 2014-12-05 21:03 +1100
          Re: The binding operator, and what gets bound to what (was: About Modifying Globals) Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-12-05 23:26 +1100
            Re: The binding operator, and what gets bound to what (was: About Modifying Globals) Chris Angelico <rosuav@gmail.com> - 2014-12-05 23:42 +1100
        Re: The binding operator, and what gets bound to what Ned Batchelder <ned@nedbatchelder.com> - 2014-12-05 07:06 -0500
          Re: The binding operator, and what gets bound to what Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-12-05 23:34 +1100
            Re: The binding operator, and what gets bound to what Chris Angelico <rosuav@gmail.com> - 2014-12-05 23:48 +1100
            Re: The binding operator, and what gets bound to what Ned Batchelder <ned@nedbatchelder.com> - 2014-12-05 07:56 -0500
  Re: About Modifying Globals "shiyao.ma" <i@introo.me> - 2014-12-05 10:53 +0800

csiph-web