我们一般不会在其它语言中遇到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)
- aws eks node 自动化扩展工具 Karpenter - 8月 10, 2022
- ReplicationController and ReplicaSet in Kubernetes - 12月 20, 2021
- public key fingerprint - 5月 27, 2021