Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

25
  • 16
    "The + operator is the "identity" operator, which does nothing." Only for numeric types; for other type it is an error by default. Commented Sep 28, 2009 at 7:47
  • 51
    Also, be aware that, in Python, += and friends are not operators that can be used in expressions. Rather, in Python they are defined as part of an "augmented assignment statement". This is consistent with the language design decision in Python to not allow assignment ("=") as an operator within arbitrary expressions, unlike what one can do in C. See docs.python.org/reference/… Commented Sep 28, 2009 at 8:06
  • 17
    The unary + operator has a use. For decimal.Decimal objects, it rounds to current precision. Commented Sep 28, 2009 at 9:10
  • 23
    I'm betting on parser simplification. Note an item in PEP 3099, "Things that will Not Change in Python 3000": "The parser won't be more complex than LL(1). Simple is better than complex. This idea extends to the parser. Restricting Python's grammar to an LL(1) parser is a blessing, not a curse. It puts us in handcuffs that prevent us from going overboard and ending up with funky grammar rules like some other dynamic languages that will go unnamed, such as Perl." I don't see how to disambiguate + + and ++ without breaking LL(1). Commented Oct 14, 2010 at 19:42
  • 11
    It's not correct to say that ++ is nothing more than a synonym for += 1. There are pre-increment and post-increment variants of ++ so it is clearly not the same thing. I agree with the rest of your points, though. Commented May 17, 2017 at 8:59