<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
zaur wrote:
<blockquote
cite="mid:afa316fa-3504-40aa-a44b-2d0aee903bfd@o35g2000vbi.googlegroups.com"
type="cite">
<pre wrap="">Python 2.6.2 (r262:71600, Apr 16 2009, 09:17:39)
[GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin
Type "copyright", "credits" or "license()" for more information.
</pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">a=1
x=[a]
id(a)==id(x[0])
</pre>
</blockquote>
</blockquote>
</blockquote>
<pre wrap=""><!---->True
</pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">a+=1
a
</pre>
</blockquote>
</blockquote>
</blockquote>
<pre wrap=""><!---->2
</pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">x[0]
</pre>
</blockquote>
</blockquote>
</blockquote>
<pre wrap=""><!---->1
I thought that += should only change the value of the int object. But
+= create new.
Is this intentional?
</pre>
</blockquote>
<br>
You don't need the (slight) complexity of += to see this. Straight
assignment shows the same behavior.<br>
<br>
Try this:<br>
a=1<br>
print id(a)<br>
a=2<br>
print id(a)<br>
<br>
The different results from the two prints happens because Python stores
integers 1 and 2 in different locations and the assignments causes a to
refer to one and then the other.<br>
<br>
Gary Herron<br>
<br>
<br>
<br>
</body>
</html>