Postfix/Prefix Operators (++,--)
Joshua Marshall
joshway_without_spam at myway.com
Fri Jun 6 13:57:32 EDT 2003
Peter Hansen <peter at engcorp.com> wrote:
> Joshua Marshall wrote:
...
>> I wouldn't design ++ to error in this case:
>>
>> >>> c = 1
>> >>> a = c++
>> >>> a
>> 1
>> >>> c
>> 2
> Except that that violates a fundamental aspect of Python, which while
> I can't describe it in the best technical terms as I don't ever work
> at the compiler level, could be said as "you are rebinding a name (c)
> without using an assignment statement".
Agreed. One reason I'm against this feature going into Python is that
I think the ability to rebind variables in expressions is a bad idea.
> I'm not sure whether there is ever a case where this is true in
> regular Python, and I suspect that if you were to attempt to
> implement this, it would require fundamental changes that would make
> Python not Python... so I'm still confident there's "no chance of
> having it, and no reason to have it."
List comprehensions let you rebind a variable in an expression, so
there is some precedent for this:
>>> c = 1
>>> a = [c - 1 for c in [c + 1]][0]
>>> a
1
>>> c
2
but I'm not fond of list comprehensions either.
More information about the Python-list
mailing list