Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

No, I had to check that, but it doesn't appear to be true. `id` uses the ptr of the object in CPython, and:

    >>> a = 1
    >>> id(a)
    32855992
    >>> a += 1
    >>> id(a)
    32855968
So it's actually creating a new Integer object, which `a` then points to, or in other words:

    a += 1 is equivalent to a = a + 1
This behavior makes sense, if you wrote:

    a = 10
    b = a
    a += 20
You wouldn't expect b to be 30.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: