Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #81976
| From | Ben Finney <ben+python@benfinney.id.au> |
|---|---|
| Subject | The binding operator, and what gets bound to what (was: About Modifying Globals) |
| Date | 2014-12-05 16:36 +1100 |
| References | <aa74bd64-0e11-492d-ae2a-4b032a0408f9@googlegroups.com> <548113f3$0$13003$c3e8da3$5496439d@news.astraweb.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.16608.1417757783.18130.python-list@python.org> (permalink) |
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
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