Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #18914
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.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; 'example:': 0.03; 'distinct': 0.05; 'python': 0.08; '>>>>': 0.09; 'programmers.': 0.09; 'received:209.85.210.174': 0.13; 'received:mail- iy0-f174.google.com': 0.13; '"+="': 0.16; "'a'": 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'subject:copy': 0.16; 'sublist': 0.16; 'wrote:': 0.16; '>>>': 0.18; '3.2': 0.18; 'jan': 0.19; 'seems': 0.19; 'header:In-Reply- To:1': 0.22; 'object,': 0.24; 'modify': 0.25; 'pm,': 0.26; 'message-id:@mail.gmail.com': 0.28; 'print': 0.29; 'fri,': 0.30; 'strings,': 0.30; 'pointing': 0.32; 'objects': 0.32; 'list': 0.32; "can't": 0.32; 'to:addr:python-list': 0.33; 'object': 0.33; 'creates': 0.34; 'normally': 0.34; 'but': 0.37; "there's": 0.37; 'received:google.com': 0.37; 'steven': 0.38; 'received:209.85': 0.38; 'point': 0.39; 'received:209': 0.39; 'subject:: ': 0.39; 'to:addr:python.org': 0.40; 'difference': 0.40; 'types': 0.61; '(always': 0.84; '11:10': 0.84; 'sorely': 0.84; 'subject:write': 0.84; 'windows)': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=psb66O65yjaasF7LhkhllRBi/6nWEvJ2y8gujlu5qts=; b=jqBhp90MPGY+w6PSJPEc2omydabZlK3bOqxRvIxaUfms0CrxCVRVdd99TwUJRVCJWq xsH/GSWNMeVut9I6QKjl1sGp6c4SldgApdjlx3oZbrv9N5Vk8r59Ew3xz9ElYNVQftzJ LkUzhuea9VQJwBJapbbUBHooVOU37PXhNW5bI= |
| MIME-Version | 1.0 |
| In-Reply-To | <4f101f45$0$29999$c3e8da3$5496439d@news.astraweb.com> |
| References | <mailman.4709.1326455724.27778.python-list@python.org> <4f101f45$0$29999$c3e8da3$5496439d@news.astraweb.com> |
| Date | Fri, 13 Jan 2012 23:30:56 +1100 |
| Subject | Re: copy on write |
| From | Chris Angelico <rosuav@gmail.com> |
| To | python-list@python.org |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | quoted-printable |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://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 | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.4712.1326457859.27778.python-list@python.org> (permalink) |
| Lines | 47 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1326457859 news.xs4all.nl 6946 [2001:888:2000:d::a6]:47553 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:18914 |
Show key headers only | View raw
On Fri, Jan 13, 2012 at 11:10 PM, Steven D'Aprano <steve+comp.lang.python@pearwood.info> wrote: >>>> z = [x, y] # z is a list containing the same sublist twice >>>> z[0].append(23) >>>> print z > [[42, 23], [42, 23]] > > When you work with floats, ints or strings, you don't notice this because > those types are immutable: you can't modify those objects in place. So > for example: > >>>> a = 42 # binds the name 'a' to the object 42 >>>> b = a # a and b point to the same object >>>> a += 1 # creates a new object, and binds it to a >>>> print b # leaving b still pointing to the old object > 42 I was about to say that it's a difference between ".append()" which is a method on the object, and "+=" which is normally a rebinding, but unfortunately: >>> a=[] >>> b=a >>> a+=[1] >>> a [1] >>> b [1] >>> b+=[2] >>> a [1, 2] >>> a [1, 2] >>> a=a+[3] >>> a [1, 2, 3] >>> b [1, 2] (tested in Python 3.2 on Windows) It seems there's a distinct difference between a+=b (in-place addition/concatenation) and a=a+b (always rebinding), which is sorely confusing to C programmers. But then, there's a lot about Python that's sorely confusing to C programmers. ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
copy on write Eduardo Suarez-Santana <esuarez@itccanarias.org> - 2012-01-13 11:33 +0000
Re: copy on write Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-01-13 12:10 +0000
Re: copy on write Chris Angelico <rosuav@gmail.com> - 2012-01-13 23:30 +1100
Re: copy on write Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-01-13 13:04 +0000
Re: copy on write Ethan Furman <ethan@stoneleaf.us> - 2012-01-13 10:40 -0800
Re: copy on write 88888 Dihedral <dihedral88888@googlemail.com> - 2012-01-13 14:26 -0800
Re: copy on write 88888 Dihedral <dihedral88888@googlemail.com> - 2012-01-13 14:26 -0800
Re: copy on write John O'Hagan <research@johnohagan.com> - 2012-02-02 14:18 +1100
Re: copy on write Devin Jeanpierre <jeanpierreda@gmail.com> - 2012-02-02 01:34 -0500
Re: copy on write John O'Hagan <research@johnohagan.com> - 2012-02-02 19:11 +1100
Re: copy on write Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-02-02 09:16 +0000
Re: copy on write Hrvoje Niksic <hniksic@xemacs.org> - 2012-02-02 11:53 +0100
Re: copy on write MRAB <python@mrabarnett.plus.com> - 2012-02-02 16:28 +0000
Re: copy on write Devin Jeanpierre <jeanpierreda@gmail.com> - 2012-02-02 12:21 -0500
Re: copy on write John O'Hagan <research@johnohagan.com> - 2012-02-03 01:17 +1100
Re: copy on write Terry Reedy <tjreedy@udel.edu> - 2012-02-02 12:25 -0500
Re: copy on write John O'Hagan <research@johnohagan.com> - 2012-02-03 14:08 +1100
Re: copy on write Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-02-03 05:04 +0000
Re: copy on write Chris Angelico <rosuav@gmail.com> - 2012-02-03 16:28 +1100
Re: copy on write Rick Johnson <rantingrickjohnson@gmail.com> - 2012-02-03 07:35 -0800
Re: copy on write Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2012-02-03 10:08 +0100
Re: copy on write John O'Hagan <research@johnohagan.com> - 2012-02-03 21:47 +1100
Re: copy on write Wolfram Hinderer <wolfram.hinderer@googlemail.com> - 2012-02-05 06:09 -0800
Re: copy on write "OKB (not okblacke)" <brenNOSPAMbarn@NObrenSPAMbarn.net> - 2012-02-03 16:15 +0000
Re: copy on write Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2012-02-02 11:42 +0100
Re: copy on write Devin Jeanpierre <jeanpierreda@gmail.com> - 2012-01-13 08:50 -0500
Re: copy on write Grant Edwards <invalid@invalid.invalid> - 2012-01-13 15:13 +0000
Re: copy on write Devin Jeanpierre <jeanpierreda@gmail.com> - 2012-01-13 11:48 -0500
Re: copy on write Neil Cerutti <neilc@norwich.edu> - 2012-01-13 16:54 +0000
Re: copy on write Grant Edwards <invalid@invalid.invalid> - 2012-01-13 18:15 +0000
Re: copy on write Chris Angelico <rosuav@gmail.com> - 2012-01-14 05:26 +1100
Re: copy on write Grant Edwards <invalid@invalid.invalid> - 2012-01-13 19:30 +0000
Re: copy on write Neil Cerutti <neilc@norwich.edu> - 2012-01-13 20:11 +0000
Re: copy on write Evan Driscoll <edriscoll@wisc.edu> - 2012-01-13 13:24 -0600
Re: copy on write Neil Cerutti <neilc@norwich.edu> - 2012-01-13 21:20 +0000
Re: copy on write Evan Driscoll <edriscoll@wisc.edu> - 2012-01-13 16:48 -0600
Re: copy on write 88888 Dihedral <dihedral88888@googlemail.com> - 2012-02-02 05:33 -0800
Re: copy on write Evan Driscoll <edriscoll@wisc.edu> - 2012-02-02 15:20 -0600
Re: copy on write 88888 Dihedral <dihedral88888@googlemail.com> - 2012-02-02 05:33 -0800
Re: copy on write 88888 Dihedral <dihedral88888@googlemail.com> - 2012-02-03 14:16 -0800
Re: copy on write 88888 Dihedral <dihedral88888@googlemail.com> - 2012-02-03 14:16 -0800
Re: copy on write Rick Johnson <rantingrickjohnson@gmail.com> - 2012-02-01 19:51 -0800
Re: copy on write Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-02-02 05:31 +0000
csiph-web