def aaa():
l = [1, 2, 3, 4, 5, 6, 7]
for i in range(len(l)):
print(i,l[i])
def bbb():
l = [1, 2, 3, 4, 5, 6, 7, 8]
index = 0
while index < len(l):
print(index, l[index])
index = index+1
#内置函数 len() 和 range(),函数 len() 返回列表的长度,即元素的个数。 range返回一个序列的数。
def ccc():
l = [1, 2, 3, 4, 5, 6, 7, 8]
for index in range(len(l)):
print(index, l[index])
print("Good bye!")
def ddd():
l = [1, 2, 3, 4, 5, 6, 7, 8]
for index in l:
print(index)
print("Good bye!")
def eee():
fruits = ['banana', 'apple', 'mango']
for fruit in fruits: # 第二个实例
print('当前水果 :', fruit)
if __name__ == '__main__':
eee()
eee():
当前水果 : banana
当前水果 : apple
当前水果 : mango
ddd():
1
2
3
4
5
6
7
8
Good bye!
ccc():
0 1
1 2
2 3
3 4
4 5
5 6
6 7
7 8
Good bye!
bbb():
0 1
1 2
2 3
3 4
4 5
5 6
6 7
7 8
aaa():
0 1
1 2
2 3
3 4
4 5
5 6
6 7