Python学习-else循环子句

from math import sqrt

for n in range(99, 82, -1):
    root = sqrt(n)
    if root == int(root):
        print(n)
        break
else: #发现这个else只有在break不执行的时候执行。这个是循环的else子句
    print("Didn't find the number!")

 

posted @ 2018-01-21 20:46  Ian_learning  阅读(254)  评论(0编辑  收藏  举报