Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #73891
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2014-07-03 02:35 -0700 |
| References | <f1cd7efe-d628-4e96-9ed3-79d9a212f768@googlegroups.com> <mailman.11432.1404356297.18130.python-list@python.org> <55f74a23-95ea-4be1-950d-e57e645dab1a@googlegroups.com> <mailman.11446.1404376617.18130.python-list@python.org> |
| Message-ID | <6ed679b1-c6e1-408e-8167-476b169fa2eb@googlegroups.com> (permalink) |
| Subject | Re: TypeError expected in an augmented assignment |
| From | candide <c.candide@laposte.net> |
> >From that link: > > > > """ > > An augmented assignment expression like x += 1 can be rewritten as x = > > x + 1 to achieve a similar, but not exactly equal effect. In the > > augmented version, x is only evaluated once. Also, when possible, the > > actual operation is performed in-place, meaning that rather than > > creating a new object and assigning that to the target, the old object > > is modified instead. > > """ > > > > The significance here is that the augmented assignment may not > > necessarily be at all comparable to the non-augmented version, but > > ought to have *approximately* the same *intention*. This is not my reading. > > of situations where the two will differ, eg when there are multiple > > references to the same object: > > > > >>> a = b = [1,2] > > >>> a += [3] > > >>> a,b > > ([1, 2, 3], [1, 2, 3]) > > >>> a = a + [4] > > >>> a,b > > ([1, 2, 3, 4], [1, 2, 3]) > > OK but this behavior is in conformance with the Reference Manual (cf. your quote above : "when possible, the actual operation is performed in-place"). This is not my point because the doc explictly claims that "an augmented assignment [...] performs the binary operation specific to the type of assignment on the two operands".
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
TypeError expected in an augmented assignment candide <c.candide@laposte.net> - 2014-07-02 19:39 -0700
Re: TypeError expected in an augmented assignment Terry Reedy <tjreedy@udel.edu> - 2014-07-02 22:57 -0400
Re: TypeError expected in an augmented assignment candide <c.candide@laposte.net> - 2014-07-03 00:51 -0700
Re: TypeError expected in an augmented assignment Chris Angelico <rosuav@gmail.com> - 2014-07-03 18:36 +1000
Re: TypeError expected in an augmented assignment candide <c.candide@laposte.net> - 2014-07-03 02:35 -0700
Re: TypeError expected in an augmented assignment Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-07-03 13:43 +0100
csiph-web