That might be the case for more complex objects...

Steve Holden steve at holdenweb.com
Sun Apr 15 12:57:25 EDT 2007


James Stroud wrote:
> Bart Willems wrote:
>> Dennis Lee Bieber wrote:
[...]
>> Lists behave as described above, integers and floats don't.
>>
>> By the way, a classic language like C has features like this too; 
>> they're called pointers.
> 
> I think that after a += 1, a memory location with a 6 is created and now 
>   a points to that because += has assignment buried in it.

This is the difference between mutable and immutable types.

  >>> a = 5
  >>> b = a
  >>> a += 1
  >>> a
6
  >>> b
5
  >>> a = [1,2,3,4,5]
  >>> b = a
  >>> a += [6,7,8]
  >>> a
[1, 2, 3, 4, 5, 6, 7, 8]
  >>> b
[1, 2, 3, 4, 5, 6, 7, 8]
  >>>

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd          http://www.holdenweb.com
Skype: holdenweb     http://del.icio.us/steve.holden
Recent Ramblings       http://holdenweb.blogspot.com




More information about the Python-list mailing list