Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why in Python, += and -= are considered as delimiters?

I am reading a tutorial about python, it's lexical structure to be more precise. And I just want to know why in Python, the:

+= , -= ,  *= ,  /= ,  //= ,  %=, <= ,  |= ,  ^= , >>= , <<=  , **= 

are considered as delimiters and not operators? After all, the "+=" is an increment operator, right?

like image 680
hanix Avatar asked Mar 19 '23 09:03

hanix


1 Answers

The syntax you refer to are used in augmented assignment statements. Like regular assignment, these are not expressions, so they are not operators either.

They happen to closely resemble certain arithmetic operators, but only in that they fall back to using those operators if the assignment target does not implement a specific augmented assignment special method for the operation.

Delimiters are tokens that do not require whitespace around them in source code, which is why those tokens are listed in that list.

like image 132
Martijn Pieters Avatar answered Mar 25 '23 09:03

Martijn Pieters