Does it use two addition operators to add two integers valid in python?

I just started learning python. I was just trying to play with the print function. I ended up writing the code below.

print(2 ++ 2)

I expected the Python interpreter to throw an error, since I put the two addition operators next to each other without putting an integer between them. In contrast, the python interpreter did not return any error and did not return 4 as output. I also tried the code below: -

print(4 -- 2)

The exit was 6.

Can someone explain this to me?

+4
source share
2 answers

2 ++ 2 interpreted as:

2 ++ 2 == 2 + (+2)

, 2 +2, + , , . , 2 +++ 2:

2 +++ 2 == 2 + (+(+2))

4 -- 2 :

4 -- 2 == 4 - (-2)

, -2 4, 6.

, ( ) , / , .

class es, (, Counter). ++ , +. , ++ ( , + ses, , + - ).

, , + - . , 2 ++--++- 2 0, :

2 ++--++- 2 == 2 + (+(-(-(+(+(-2))))))
+5
2 ++ 2

2 + (+2)

4 -- 2

4 - (-2)

, :

2 ==+-+-+ 2
#>>> True

, + , - ( , -- ); Python , , .

+4

Source: https://habr.com/ru/post/1678983/


All Articles