python--循环
while 循环
# continue 和 break 用法
i = 1
while i < 10:
i += 1
if i%2 > 0:
# 非双数时跳过输出continue
print i
# 输出双数2、4、6、8、10
i = 1
while 1:
# 循环条件为1必定成立
print i
# 输出1~10
i += 1
if i > 10:
# 当i大于10时跳出循环
break
For循环
#!/usr/bin/python
# -*- coding: UTF-8 -*-
for letter in 'Python':
# 第一个实例
print '当前字母 :', letter
fruits = ['banana', 'apple', 'mango']
for fruit in fruits:
# 第二个实例
print '当前水果 :', fruit
print "Good bye!"

浙公网安备 33010602011771号