Compound Assignment Operators ( +=, *=, etc...)
Timothy R Evans
tre17 at pc142.cosc.canterbury.ac.nz
Fri Aug 20 02:46:45 CEST 1999
Tom Christiansen <tchrist at mox.perl.com> writes:
> [courtesy cc of this posting mailed to cited author]
> In comp.lang.python,
> Timothy R Evans <tre17 at pc142.cosc.canterbury.ac.nz> writes:
> def foo():
> x = x + 2
> return x
> That's not legal even now. You need the global.
Oops, you're right of course, you can access globals but you can't
override a global definition if you have already used the global
value. Quite strange behaviour really.
x = 5
print x # works, prints 5
x = 6 # works, but doesn't change the global
x = 6 # this fails with NameError
Seems like a good behaviour as it stops you doing dumb things.
More information about the Python-list