我雖然比較的代碼:無限,而在Python循環時,整數與範圍
i=0
a = range(100)
while i < range(100):
print i
i += 9
此進入一個無限循環......可我知道爲什麼嗎?
是因爲一個整數與列表進行比較? 但是當我變得大於99時會發生什麼?
不應該它出來的while循環?
下面的代碼工作正常預期:
i=0
a = range(100)
a_len = len(a)
while i < a_len:
print i
i += 9