-6
A
回答
0
即不僅蟒,也就是在大多數編程語言
X = 1的; x + = 1; x將是2
x = 1; x- = 1; x將爲0
x = 3; x * = 2; x將是6
x = 6; x/= 2; x是3
0
他們正在執行的操作,然後將其分配到變量:
a += b
是相同的a = a + b
a -= b
是相同的a = a - b
a *= b
是一樣a = a * b
a /= b
與相同
您可以在while
循環以同樣的方式使用它們,你將使用擴展形式:
i = 0
while i < 5:
print i
i += 1 # The same of i = i + 1
0
很肯定這是教師如何「早在天」會處理這個問題:
i = 2
while i != 1:
print "I will first do basic research."
i += 1
i *= 1
i /= 1
i -= 1
0
這些都是運營商分配的速記:
Operator symbol Name of the operator Example Equivalent construct
+= Addition assignment x += 4; x = x + 4;
-= Subtraction assignment x -= 4; x = x - 4;
*= Multiplication assignment x *= 4; x = x * 4;
/= Division assignment x /= 4; x = x/4;
%= Remainder assignment x %= 4; x = x % 4;
1
這些(+=
,-=
,*=
和/=
)被稱爲augmented arithmetic assignments。它們對應於下列方法:
object.__iadd__(self, other)
object.__isub__(self, other)
object.__imul__(self, other)
object.__idiv__(self, other)
的i
語義的意思是「就地」,這意味着它們修改對象(或數字組成的情況下參考),而不必額外地將它們分配:
while condition:
foo += bar
等同於:
while condition:
foo = foo + bar
相關問題
- 1. 什麼和python代表
- 2. @UndefinedVariable在Python中代表什麼?
- 3. 「stdio」和「stdlib」在C中代表什麼?
- 4. 在文檔中,'['和']'代表什麼?
- 5. ' - '在bash中代表什麼?
- 6. []在C#中代表什麼#
- 7. 「nib」和「xib」代表什麼?
- 8. MKAnnotation和MKAnnotationView代表什麼?
- 9. brk和sbrk代表什麼?
- 10. Python的dir()函數代表什麼?
- 11. #在C++代碼中代表什麼?
- 12. 在Python 3中替代xreadlines()是什麼?
- 13. 「ModLoad」在Python代碼中做了什麼?
- 14. 在makefiles CC和LD代表什麼?
- 15. Python/Django:這行代表什麼?
- 16. 在lex.yy.c查找表中代表什麼?
- 17. 什麼是在C#中的事件和代表的替代?
- 18. 什麼是lambda在這個python代碼中做什麼?
- 19. 在Python中列表和列表[:]之間有什麼區別?
- 20. 爲什麼列表在Python和Java中表現不同?
- 21. 「我」在Python .pyi擴展中代表什麼?
- 22. ./(點斜線)運算符在Python中代表什麼?
- 23. 在Python中的字符串之前,'r'代表什麼?
- 24. 在Python下的OpenERP開發中,ir.sequence代表什麼?
- 25. []代表什麼?
- 26. _model在symfony/propel中代表什麼?
- 27. gm和mk在gmtime()和mktime()中代表什麼?
- 28. testenv代表什麼?
- 29. <?>在Java中代表什麼?
- 30. Python忽略什麼在列表中?
他們是速記的運營商。 – thefourtheye
我認爲[你需要一本編程書籍](http://openbookproject.net/thinkcs/python/english3e/)讓你比現在更進一步。 – JFA
嗨,既然你是新人,你應該知道,如果你接受一個答案(點擊最好回答你的問題的答案旁邊的複選標記),你會得到+2代表。不多,但是這是一些東西。 –