我们一般不会在其它语言中遇到for 循环和 while循环后跟 else
但是在Python中我们会
else的意义在于执行完所有循环之后,再执行else模块,注意,break会跳过else模块
看例子:
1 2 3 4 5 6 7 8 9 10 11 12 |
def showMaxFactior(num): count = num / 2 while count > 1: if num % count == 0 : print 'largest factor is :%s ' % count break count -= 1 else: print 'is Prive' for eachItem in range(20): showMaxFactior(eachItem) |
Latest posts by Zhiming Zhang (see all)
- istio Ingress Gateways - 十一月 25, 2020
- Istio VirtualService - 十一月 23, 2020
- istio 组件 - 十一月 18, 2020