why cannot assign to function call

anthony.tolle at gmail.com anthony.tolle at gmail.com
Mon Dec 29 16:46:26 CET 2008


On Dec 29, 1: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

Probably the closest thing you are going to get in Python would be the
following:

>>> class C:
...     pass
...
>>> def f(a):
...     return a
...
>>> b = C()
>>> b.value = 0
>>> b.value
0
>>> f(b).value = 1
>>> b.value
1

But as others have pointed out, Python is not C/C++, and shouldn't be
treated as such.



More information about the Python-list mailing list