好久沒有學習了
例1.循環遍歷
for letter in 'Python': # 第一個實例
print '當前字母 :', letter
fruits = ['banana', 'apple', 'mango']
for fruit in fruits: # 第二個實例
print '當前水果 :', fruit
print "Good bye!"
輸出結果如下:
例2.序列索引迭代
len()和range(),len()返回列表的長度,range()返回一個序列的數。
ws = ['hello', 'world', 'bye']
for index in range(len(ws)):
print '當前輸出 :', ws[index]
print "Good bye!"
輸出如下: