1、Python While 循环语句

while 判断条件:
    执行语句……

当判断条件为true时,进入循环。

返当判断条件为false时,循环结束。

Python学习基础篇5------循环语句

2、循环使用else 语句、

在Python中,while...else在循环添加为false时 执行else语句。

count = 0 while count < 5:

     print count, " is less than 5"

     count = count + 1

else:

     print count, " is not less than 5"

以上实例输出结果为:

0 is less than 5
1 is less than 5
2 is less than 5
3 is less than 5
4 is less than 5
5 is not less than 5

3、简单语句组(将while循环中只有一句话)

flag=1

while (flag) : print 'Given flag is really true!'

print "Good bye!"

注意:以上的无限循环你可以使用 CTRL+C 来中断循环。

 

相关文章:

  • 2021-12-05
  • 2021-12-18
  • 2021-12-12
  • 2021-03-26
  • 2021-12-05
  • 2021-09-17
猜你喜欢
  • 2021-12-18
  • 2021-12-05
  • 2021-12-05
  • 2021-09-20
  • 2018-06-14
  • 2021-11-04
  • 2021-11-14
  • 2021-12-05
相关资源
相似解决方案