newbie looking for help, int reference question
exarkun at intarweb.us
Wed Jan 15 06:42:23 CET 2003
On Wed, Jan 15, 2003 at 07:15:15AM +1300, Andrew McGregor wrote:
> Assignment is a statement (not an expression) which binds the name(s) on
> the LHS to the value(s) on the RHS. The += forms mean the same as their
> expansion, so
> i += 10
> really is the same as
> i = (i + 10)
> and means 'rebind the name i to the object returned by the expression i +
Ahhh, no. += is only sometimes semantically equal to the ... = ... + ...
expansion. This is the source of much confusion, and a good reason to avoid
+= altogether. Here are a few examples to demonstrate...
def foo(x, y):
x += y
x = foo(, range(3))
print foo(x, x)
And, of course, my personal favorite:
x = (,)
x += [None]
This doesn't have much to do with the original question, but if the use of
+= is avoided, the behavior exhibited should become quite clear.
If it jams -- force it. If it breaks, it needed replacing anyway.
12:00am up 30 days, 9:47, 3 users, load average: 0.39, 0.25, 0.25
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 196 bytes
Desc: not available
More information about the Python-list