Home  >  Article  >  Backend Development  >  python中循环语句while用法实例

python中循环语句while用法实例

WBOY
WBOYOriginal
2016-06-06 11:17:041714browse

本文实例讲述了python中循环语句while用法。分享给大家供大家参考。具体分析如下:

对于python的while语句,注意其缩进即可。 python和其他语言一样也有break和continue,分别用来表示跳出循环和继续循环。

#!/usr/bin/python
# Simple while loop
a = 0
while a < 15:
  print a, # 在print a后面加,不换行
  if a == 10:
    print "made it to ten!!"
  a = a + 1

运行结果如下:

0 1 2 3 4 5 6 7 8 9 10 made it to ten!!
11 12 13 14

希望本文所述对大家的Python程序设计有所帮助。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn