why cannot assign to function call

James Mills prologic at shortcircuit.net.au
Mon Dec 29 07:08:22 CET 2008


On Mon, Dec 29, 2008 at 4:01 PM, scsoce <scsoce at gmail.com> wrote:
> I have a function return a reference, and want to assign to the reference,
> simply like this:
>>>def f(a)
>         return a
>    b = 0
>   * f( b ) = 1*
> but the last line will be refused as "can't assign to function call".
> In my thought , the assignment is very nature,  but  why the interpreter
> refused to do that ?

That's exactly right. You _cannot_ assign to a function call.
This is invalid in just about _all_ languages.

Assignments are generally bound to a variable.

>>> def f(a):
...     return a
...
>>> b = 0
>>> x = f(b)
>>> x
0
>>>

cheers
James



More information about the Python-list mailing list