当我们按 "for item in list:" 遍历列表时,我们可以确保 for 循环迭代顺序吗?

Can we insure the for loop iteration order when we loop over a list by "for item in list:"?

for a in mylist:
     print(a)

我想知道for循环迭代中的项目是否总是按顺序打印项目?

我知道"for i in (len(mylist))"可以保证顺序但不确定"for a in mylist"是否可以保证顺序。

我在我的电脑上试过,它似乎按顺序打印出项目。但不确定是不是到处都是

谢谢

一句话-是的。引用 Python's wiki(为强调而添加粗体):

The Python for statement iterates over the members of a sequence in order, executing the block each time.