Python中"iterable","iterator"和"iteration"的最基本定义是什么?
我已阅读多个定义,但我无法确定其确切含义,因为它仍然不会沉入其中.
有人可以帮助我解释外行人的3个定义吗?
我无法理解为什么以下代码无限循环(当我不使用副本列表时)
list = ["Mohit","kumar","sffsfshfsd"]
for w in list:
if(len(w)) > 5:
list.insert(0,w)
print("inside loop")
print(list)
Run Code Online (Sandbox Code Playgroud)
上面的代码无限期地打印在循环内部.
现在,如果代替列表,我使用下面的副本列表工作正常.
list = ["mohit","kumar","sffffgssddf"]
for w in list[:]:
if len(w) > 5:
list.insert(0,w)
print("inside loop")
print(list)
Run Code Online (Sandbox Code Playgroud)
现在我已经在python文档中读到这是我将得到的行为,但我想了解它背后的原因.提前致谢.
python ×3
for-loop ×1
iterable ×1
iteration ×1
iterator ×1
list ×1
python-2.x ×1
python-3.x ×1
terminology ×1