Python循环结构笔记:while与for循环详解及实例.pdfVIP

  • 1
  • 0
  • 约4.51千字
  • 约 6页
  • 2026-04-16 发布于北京
  • 举报

Python循环结构笔记:while与for循环详解及实例.pdf

笔记

:智泊AI

作者:Jeff

⼀.循环【重点掌握】

1.while循环

#语法:

1.初始化的表达式

i=1

while2.条件表达式:

i=100

循环体(重复执⾏的代码⽚段)

3.更新表达式

i+=1

执⾏流程:

先执⾏初始条件,然后判断循环条件是否满⾜,若满⾜循环条件,则执⾏循环,若不满⾜循环条件,结束循环.

#注意:初始化的表达式只会在第⼀次循环的时候执⾏⼀次

代码演示:

#输出100遍的helloworld

print(helloworld)

print(helloworld)

print(helloworld)

print(helloworld)

print(helloworld)

print(helloworld)

print(helloworld)

print(helloworld)

print(helloworld)

#1.初始化表达式定义⼀个变量初始值为0

i=0

whilei=99:

#2.设置表达式的终⽌条件(循环结束的条件)

print(helloworld)

#3

文档评论(0)

1亿VIP精品文档

相关文档