In article <[EMAIL PROTECTED]>,
Roel Schroeven <[EMAIL PROTECTED]> wrote:
>
>I used to interpret the target in 'The target is only evaluated once'
>more like an L-value in C/C++. That's not correct, of course, but I
>didn't understand exactly how wrong it was until now.
It's true almost everywh
In article <[EMAIL PROTECTED]>,
OKB (not okblacke) <[EMAIL PROTECTED]> wrote:
>
> This sentence is phrased as though it is the whole story, but it
>isn't, because the operation might not in fact wind up being an
>assignment. Shouldn't there be an "except see below" or something
>there, to
OKB (not okblacke) schreef:
> Aahz wrote:
>
>>> tup=([],)
>>> tup[0] += ['zap']
Traceback (most recent call last):
File "", line 1, in
TypeError: 'tuple' object does not support item assignment
>
>> Obviously, you can easily work around it:
>>
> t = ([],)
> l = t
Aahz wrote:
>> tup=([],)
>> tup[0] += ['zap']
>>> Traceback (most recent call last):
>>> File "", line 1, in
>>> TypeError: 'tuple' object does not support item assignment
> Obviously, you can easily work around it:
>
t = ([],)
l = t[0]
l += ['foo']
t
> (['foo'],)
Aahz schreef:
def foo(bar): bar[0] += ['zap']
> ...
import dis
dis.dis(foo)
> 1 0 LOAD_FAST0 (bar)
> 3 LOAD_CONST 1 (0)
> 6 DUP_TOPX 2
> 9 BINARY_SUBSCR
> 10 LOAD_
In article <[EMAIL PROTECTED]>,
Roel Schroeven <[EMAIL PROTECTED]> wrote:
>Aahz schreef:
>>
>> Although Alex is essentially correct, the situation is a bit more complex
>> and you are correct that augmented assignment allows the object to decide
>> whether to mutate in place. However, the critic
Aahz schreef:
> In article <[EMAIL PROTECTED]>,
> Neil Cerutti <[EMAIL PROTECTED]> wrote:
>> On 2007-08-11, Alex Martelli <[EMAIL PROTECTED]> wrote:
>>> Neil Cerutti <[EMAIL PROTECTED]> wrote:
>>>...
The Python Language Reference seems a little confused about the
terminology.
>>
Terry Hancock wrote:
> On Tue, 21 Feb 2006 10:55:42 +0530
> Suresh Jeevanandam <[EMAIL PROTECTED]> wrote:
> Seriously,
> I think they are usually equivalent internally,
> at least for immutable objects.
>
yah, but when you do augmented assigns on lists, or mix immutable an
dmutable:
http://zeph
On Tue, 21 Feb 2006 10:55:42 +0530
Suresh Jeevanandam <[EMAIL PROTECTED]> wrote:
> Is there any gain in performance because of
> augmented assignments.
>
> x += 1 vs x = x+1
Yep. I perform better when I only type names once.
Especially if they are long:
length_of_object_I_must
<[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>
> Terry Reedy wrote:
>> Program performance might be noticeable if 'x' is something like a.b.c.d
>> that takes some lookup time. But again, I would use the += form for
>> readability without testing run time.
>
> Would x=x + 1 be more
I think it heavily depends on what is "x". If x is bound to a mutable
x=x+1 and x+=1 can not only have different speed but indeed can do two
very unrelate things (the former probably binding to a new object, the
latter probably modifying the same object). For example consider what
happens with list
Terry Reedy wrote:
> Program performance might be noticeable if 'x' is something like a.b.c.d
> that takes some lookup time. But again, I would use the += form for
> readability without testing run time.
Would x=x + 1 be more readable, regardless of the background(whether
being introduced to the
Thanks Alex. I was not aware of mtimeit.
regards,
Suresh
Alex Martelli wrote:
> Suresh Jeevanandam <[EMAIL PROTECTED]> wrote:
>
>> Hi,
>> Is there any gain in performance because of augmented assignments.
>>
>> x += 1 vs x = x+1
>>
>> Or are both of them the same.
>
> Just *MEASURE*
"Suresh Jeevanandam" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hi,
> Is there any gain in performance because of augmented assignments.
>
> x += 1 vs x = x+1
>
> Or are both of them the same.
The main gain is in programmer performance for writing a long name such as
number_
Suresh Jeevanandam <[EMAIL PROTECTED]> wrote:
> Hi,
> Is there any gain in performance because of augmented assignments.
>
> x += 1 vs x = x+1
>
> Or are both of them the same.
Just *MEASURE*, man!
helen:~/apy alex$ python -mtimeit -s'x=0.0' 'x=x+1'
100 loops, best of 3: 0.507
15 matches
Mail list logo