davea at ieee.org
Sat Nov 13 21:54:31 CET 2010
On 2:59 PM, Mark Wooding wrote:
> Tracubik<affdfsdfdsfsd at b.com> writes:
>>>>> def change_integer(int_value):
>> ... int_value = 10
> Alas, Python is actually slightly confusing here, since the same
> notation `=' sometimes means assignment and sometimes means mutation.
> You can tell which is which by looking at the left hand side: if it's a
> simple variable name, the variable is assigned a new value; if it's
> something more complicated (e.g., indexing (`foo'), or attribute
> selection (`foo.bar') then some mutation is (probably) going to happen:
No, an (=) assignment is always an assignment. It changes the item on
the left hand side to refer to a new object. But if the item on the
left hand side is not a simple variable, then generally only part of its
contents refers to a new object, rather than the variable itself.
For example, mylist = "abc" is assigning a new object to a member of
the list, but does not make a new list, replacing the whole list.
Your other points, such as about the augmented assignment, are quite
More information about the Python-list