章节
Python 介绍Python 开发环境搭建Python 语法Python 变量Python 数值类型Python 类型转换Python 字符串(String)Python 运算符Python 列表(list)Python 元组(Tuple)Python 集合(Set)Python 字典(Dictionary)Python If … ElsePython While 循环Python For 循环Python 函数Python LambdaPython 类与对象Python 继承Python 迭代器(Iterator)Python 模块Python 日期(Datetime)Python JSONPython 正则表达式(RegEx)Python PIP包管理器Python 异常处理(Try…Except)Python 打开文件(File Open)Python 读文件Python 写文件Python 删除文件与文件夹
Python While 循环
Python循环
Python有两个基本的循环语句:
while 循环for 循环
While 循环
while循环,只要条件为真,会一直执行。
示例
只要i小于10,打印i:
i = 1
while i < 10:
print(i)
i += 1
注意: 记住增加i,否则循环将永远执行。
break 语句
break语句用于跳出循环:
示例
当i为5时跳出循环:
i = 1
while i < 10:
print(i)
if i == 5:
break
i += 1
Doc navigation
← Python If ... Else
Python For 循环 →