Why compiler doesn't support in(de)crement operation? Should we support it?

I am curious why python doesn’t support pre-increment/decrement operator. Do we have any formal conclusion/

much discuss in:

  1. https://bugs.python.org/issue37304
  2. https://stackoverflow.com/questions/1485841/behaviour-of-increment-and-decrement-operators-in-python
  3. https://hackernoon.com/modifying-the-python-language-in-7-minutes-b94b0a99ce14

IMO, the links you post pretty much cover it. Python is not C, and has managed for a long time without ++ and – operators. Also, Python distinguishes between operators and statements. Augmented assignment (+=) is a statement, would you have ++ be a statement (which makes it mostly useless) or an operator (with unexpected assignment semantics)?

Basically ++ and – don’t fit well with Python, and aren’t needed. I’m -1.


Thanks for the idea.

Agreed. It’s really just an implicit syntactic shortcut (which Python has a tendency to avoid). I find it difficult to imagine a scenario where you couldn’t just use +=, enum() or next() instead.

Although I’m not opposed to the idea of ++i raising a SyntaxError, as mentioned on the bpo issue.

Thanks, guys. I have this question because i found c、java and js support this satetement.

Although I’m not opposed to the idea of ++i raising a SyntaxError , as mentioned on the bpo issue.

kyle abserved this detail :slight_smile: If the python object is immutable object, we don’t support such complex statement, should we raise the syntaxError when user use ++i too.

ps: i found some scan tool have this check rule, such as: sonarqube