SyntaxError: can't assign to a function call
Alex Martelli
aleaxit at yahoo.com
Sun Feb 26 18:49:59 EST 2006
Fuzzyman <fuzzyman at gmail.com> wrote:
> What gives ?
...
> >>> a = []
> >>> def f():
> return a
...
> >>> f() += [4]
> SyntaxError: can't assign to function call
Exactly what the error message says: it's syntactically forbidden to
perform any assignment on a function-call.
If you're keen on these semantics, use for example
f().extend([4])
which IS quite legal (or, if you know the RHS list has only one item,
f().append(4) is clearer and more effective).
Alex
More information about the Python-list
mailing list