"+ ="和"= +"之间的区别?

问题描述:

所以我有一段简单的代码可以打印出整数1-10:

So I have a simple piece of code that prints out the integers 1-10:

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

然后,如果仅在第3行上更改一个运算符,它将打印出无限数量的1整数(我知道为什么会这样做).为什么在运行第二个程序时没有出现语法错误?如果赋值运算符后面跟着一个加法运算符,它不会调用语法错误吗?

Then if you just change one operator around on line 3, it prints out an infinite amount of 1 integers(which i understand why it does that). Why isn't a syntax error occurring when running this second program? Wouldn't it call a syntax error in the event of an assignment operator being followed by an addition operator??

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

i+=1i=i+1相同,而 i=+1仅表示i=(+1).

i+=1 is the same as i=i+1, whereas i=+1 just means i=(+1).