Why is there no post-pre increment operator in python
tim.peters at gmail.com
Fri Jan 13 04:57:10 CET 2006
[riteshtijoriwala at gmail.com]
> Anyone has any idea on why is there no post/pre increment operators in
> python ?
Maybe because Python doesn't aim at being a cryptic portable assembly
language? That's my guess ;-)
> Although the statement:
> works but does nothing
That depends on the type of j, and how it implements the __pos__()
method. The builtin numeric types (integers, floats, complex)
implement __pos__ to return the base-class part of `self`. That's not
the same as doing nothing. There is no "++" operator in Python, BTW
-- that's two applications of the unary-plus operator.
>>> class MyFloat(float):
>>> x = MyFloat(3.5)
>>> type(+x) # "downcasts" to base `float` type
>>> type(x.__pos__()) # same thing, but wordier
If you want, you can implement __pos__ in your class so that
posts messages to comp.lang.c asking why C is so inflexible ;-).
More information about the Python-list