The difference between "+ =" and "= +"?

So, I have a simple piece of code that outputs integers 1-10:

i = 0
while i < 10:
        i += 1
        print(i)

Then, if you just change one statement to line 3, it produces an infinite number of 1 integers (which I understand why it does this). Why is there no syntax error when starting this second program? Wouldn't that cause a syntax error if the assignment operator is followed by the addition operator?

i = 0
while i < 10:
        i =+ 1
        print(i)
+4
source share
5 answers

i+=1matches with i=i+1, whereas it i=+1means only i=(+1).

+17
source

, (, , ).

, x=+y, x =+ y x = +y , + y x. , , , , .

, --> " C/++ .. , , , , .

+5

i =+ 1 i = +1 i = 1.

+2

x=+1 : x=(+1)
x+=1 : x=x+1

, (, * ).
, (, ~/! ). , .

python , .

Python:

- () .

+ () .

+1

There is no syntax error because the expression i =+ 1matches i = (+1)and is +1perfectly legal. This is a unary operator, not an addition operator.

0
source

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


All Articles