On 2:59 PM, Mark Wooding wrote:
Tracubik<affdfsdfds...@b.com>  writes:

def change_integer(int_value):
...     int_value = 10
...
<snip>

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[0]'), 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[4] = "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 useful, however.

DaveA

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to