首页 > 技术文章 > 《与小卡特一起学Python》 Code5 for循环

ccccnzb 2016-03-15 15:36 原文

1 import time
2 for i in range(10,0,-1):
3     print i
4     time.sleep(1)
5 print "Blast off!"

以上代码循环意思为:

从10 到 1 每次递增-1,并睡眠1秒

最后跳出for,打印“Blast off”

Python的代码块,用缩进来表示,不是大括号,需要注意代码的缩进程度

推荐阅读