其基本形式为:
while 判断条件(condition): 执行语句(statements)……
执行语句可以是单个语句或语句块。判断条件可以是任何表达式,任何非零、或非空(null)的值均为True。
当判断条件为假 False 时,循环结束。


举例1:
y=0
while y<10:
print(y)
y=y+1
结果:
0
1
2
3
4
5
6
7
8
9
例题2:
count = 0
while count < 9:
print ('The count is:',count)
count = count + 1
print("Good bye!")
以上代码执行输出结果:
The count is: 0
The count is: 1
The count is: 2
The count is: 3
The count is: 4
The count is: 5
The count is: 6
The count is: 7
The count is: 8
Good bye!
相关文章:
python,for循环 2024-04-09
Python 条件语句 2024-03-27
Python 运算符 2024-03-27
Python 变量类型 2024-03-27
第二节:python的input函数用法 2024-03-26
十进制数二进制相互转换(知识和题目)2025-06-24
编码的基本方式和应用(知识和选择题)2025-06-24
攀枝花大河中学介绍(国家级重点特色高中)2025-02-19
小学音乐教师年终工作总结四(整理3篇)2024-01-24
教科室春季学期工作总结范文2024-01-23