for 變數 in 序列:
語句 1
else:
語句2
languages = ["C#", "Java", "Python"] for x in languages: print(x)上述程式碼的執行結果如下所示:
>>> languages = ["C#", "Java", "Python"]
>>> for x in languages:
print(x)
C#
Java
Python
for i in range(4): print(i)上述程式碼的執行結果如下所示:
>>> for i in range(4):
print(i)
0
1
2
3
languages = ["C#", "Java", "Python"] for i in range(len(languages)): print(i, languages[i])上述程式碼的執行結果如下所示:
>>> languages = ["C#", "Java", "Python"]
>>> for i in range(len(languages)):
print(i, languages[i])
0 C#
1 Java
2 Python