In article <[EMAIL PROTECTED]>,
Tim Roberts <[EMAIL PROTECTED]> 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
"Fuzzyman" <[EMAIL PROTECTED]> wrote:
>
>Alex Martelli wrote:
>> Fuzzyman <[EMAIL PROTECTED]> wrote:
>>
>> > What gives ?
>>...
>> > >>> a = []
>> > >>> def f():
>> > return a
>>...
>> > >>> f() += [4]
>> > SyntaxError: can't assign to function call
>>
>> Exactly what the error messa
Fuzzyman <[EMAIL PROTECTED]> wrote:
...
> > Exactly what the error message says: it's syntactically forbidden to
> > perform any assignment on a function-call.
...
> Cool, thanks. That's what I did, it's just not an error I'd seen
> before. Everywhere else Python evaluates the function call a
Alex Martelli wrote:
> Fuzzyman <[EMAIL PROTECTED]> 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 an
"Fuzzyman" <[EMAIL PROTECTED]> writes:
f() += [4]
> SyntaxError: can't assign to function call
It's obvious that that line gives you a syntax error. += is the increment
operator overloaded for strings and lists and so on. It changes the lhs in
place appending the rhs. In this case the
Fuzzyman <[EMAIL PROTECTED]> 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 ke
What gives ?
>>> a = []
>>> def f():
return a
>>> f()
[]
>>> a.append(3)
>>> f()
[3]
>>> a += [3]
>>> a
[3, 3]
>>> f()
[3, 3]
>>> f() += [4]
SyntaxError: can't assign to function call
>>>
Fuzzyman
http://www.voidspace.org.uk/python/index.shtml
--
http://mail.python.org/mailman/listinf