SyntaxError: can't assign to a function call

Aahz aahz at pythoncraft.com
Wed Mar 1 03:00:37 CET 2006


In article <on65021qdcolmvuj0ammt58k35ok14qq46 at 4ax.com>,
Tim Roberts  <timr at probo.com> wrote:
>
>One thing that can be helpful in situations like this is to remember that
>+= in Python isn't quite as "special" as it is in C.  So,
>
>  f() += [4]
>
>is the same as
>
>  f() = f() + [4]
>
>and I think you can see why that is a problem.

Actually, it's not quite the same as the expansion, either:

>>> a=[1]
>>> b=a
>>> a+=[2]
>>> a is b
1
>>> a = a + [3]
>>> a is b
0
>>> a
[1, 2, 3]
>>> b
[1, 2]
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"19. A language that doesn't affect the way you think about programming,
is not worth knowing."  --Alan Perlis



More information about the Python-list mailing list