why cannot assign to function call

r rt8396 at gmail.com
Mon Dec 29 01:14:36 EST 2008


On Dec 29, 12:01 am, scsoce <scs... 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 ?
>
> thks

because all you need to do is
>>> b = 1

trying to change the return value of a function before you even "know
what it is" so to speak, defeats the whole purpose of sending it there
in the first place. just assign the variable to a new value. Thats my
common sense answer, maybe somebody can give a technical one :)



More information about the Python-list mailing list