"+ ="和"= +"之间的区别? [英] The difference between '+=' and '=+'?
本文介绍了"+ ="和"= +"之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我有一段简单的代码可以打印出整数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+=1
与i=i+1
相同,而
i=+1
仅表示i=(+1)
.
i+=1
is the same as i=i+1
, whereas
i=+1
just means i=(+1)
.
这篇关于"+ ="和"= +"之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文