Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #81943
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.005 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'element': 0.07; 'assigning': 0.09; 'function,': 0.09; 'cc:addr:python-list': 0.11; 'def': 0.12; '"a"': 0.16; '"b"': 0.16; 'assigns': 0.16; 'change;': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'referencing': 0.16; 'subscripted': 0.16; 'wrote:': 0.18; 'replacing': 0.19; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'second': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'dec': 0.30; 'message-id:@mail.gmail.com': 0.30; 'object.': 0.31; 'second,': 0.31; 'subject:About': 0.31; 'fri,': 0.33; 'actual': 0.34; 'but': 0.35; 'received:google.com': 0.35; 'two': 0.37; 'new': 0.61; "you're": 0.61; 'first': 0.61; 'name': 0.63; 'to:none': 0.92 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=qv9nOirBhm3sV70WIhwtdL33EDY7XtUk6HeJt2JII8k=; b=YaJUX+vcsqx8GZQokiwZkefveN6zkGzFue4bacUkOP7PyqJCskcvQRCl1Vu8HPOI9X 3zaHTOLx6h/6plPQ3GoEfyDiqw9AbSXVEJeWChx/ulKLyI1s3gHNu6/eOJs/Ncdd4S2H 0n+vvitiksZit0K8VdohRqMDOV29UQbKUmZiAxQaOgbIZAsp9OcbhjOSsH2W0buoj5C5 qgHLD0+JHovUnqsyWD5xunR61V4+OR7Tk+S9L+ph1AFivx/9wedJBhGxbvZXrpoVIVG4 /tcMppm78x3H0yHsKBbZ9Jc9RVCpj9pawrsi4y05jmOiRo+Xn2/SZIZnQq4w8WjHenwn 9D6w== |
| MIME-Version | 1.0 |
| X-Received | by 10.42.130.194 with SMTP id w2mr13064100ics.12.1417724535567; Thu, 04 Dec 2014 12:22:15 -0800 (PST) |
| In-Reply-To | <aa74bd64-0e11-492d-ae2a-4b032a0408f9@googlegroups.com> |
| References | <aa74bd64-0e11-492d-ae2a-4b032a0408f9@googlegroups.com> |
| Date | Fri, 5 Dec 2014 07:22:15 +1100 |
| Subject | Re: About Modifying Globals |
| From | Chris Angelico <rosuav@gmail.com> |
| Cc | "python-list@python.org" <python-list@python.org> |
| Content-Type | text/plain; charset=UTF-8 |
| 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.16583.1417724539.18130.python-list@python.org> (permalink) |
| Lines | 18 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1417724539 news.xs4all.nl 2902 [2001:888:2000:d::a6]:38383 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:81943 |
Show key headers only | View raw
On Fri, Dec 5, 2014 at 7:09 AM, LJ <luisjosenovoa@gmail.com> wrote: > def gt(l): > a["1"] = a["1"] | set([l]) > > > def gt2(l): > b=b+l These two may both look like they're assigning something, but one of them is assigning directly to the name "b", while the other assigns to a subscripted element of "a". In the first function, "a" is still the same object after the change; in the second, "b" has been replaced by a new object. That's why your second one needs a global declaration. It's all about names and assignment; if you're not assigning to the actual name, there's no need to declare where the name comes from, because you're only referencing it, not replacing it. ChrisA
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