f---ing typechecking

Delaney, Timothy (Tim) tdelaney at avaya.com
Tue Feb 20 17:16:46 EST 2007


Nick Craig-Wood wrote:

>     x += a
> 
> does not equal
> 
>     x = x + a
> 
> which it really should for all types of x and a

Actually, this will *never* be the case for classes that do in-place
augmented assignment.

    a = [1]
    b = [2]

    c = a + b
    print a, b, c

    a += b
    print a, b, c

You'll note that I didn't rebind 'a' in the non-augmented assignment. If
you do, augmented and non-augmented assignment may look the same, but
they can be very different.

Tim Delaney



More information about the Python-list mailing list