Day11:while循环

Python程序语言总共有二种回圈的语法。第一种是"for"回圈,另外一个则是"while"。

让我们来看看以下的程序码吧~

[In]
x=0
numbers=[]

while x <6: #当变数大於6中断回圈
    print(f"At the top is  {x}")
    numbers.append(x) #把X增加到串列里面
    x=x+1
    print("Numbers now:"),numbers
    print(f"{x} is at the bottom")
    print("The numbers:")
for number in numbers:


     print(number)
[Out]
At the top is  0
Numbers now:
1 is at the bottom
The numbers:
At the top is  1
Numbers now:
2 is at the bottom
The numbers:
At the top is  2
Numbers now:
3 is at the bottom
The numbers:
At the top is  3
Numbers now:
4 is at the bottom
The numbers:
At the top is  4
Numbers now:
5 is at the bottom
The numbers:
At the top is  5
Numbers now:
6 is at the bottom
The numbers:
0
1
2
3
4
5

总结:

while和for最大的不一样就是while-loop会直到他对应的布林表达式为False才会停下来。

Source:

https://ppt.cc/fopYQx
https://ppt.cc/f23jJx


<<:  Python侦测VPN网路是否可连线 - Python练习题二

>>:  【左京淳的JAVA WEB学习笔记】第五章 过滤器与监听器

D02 - 集结硬体小夥伴

首先我们先将硬体准备完成,需要准备的设备有: 基本设备 Arduino Uno 常见且容易取得的 U...

[VSCodeVim] Vim的思维、哲学与解决问题之道

Vim的思维、哲学与解决问题之道 [系列文目录] 每种工具都有它的设计理念,在接触Vim的前後,我们...

Day16 Vue directives(v-model资料双向绑定)

在Vue里有个很大的特色可能就是资料的双向绑定(Two-wayBinding),而资料绑定的话我们最...

[Day 17] 阿嬷都看得懂的程序码编辑器与开源软件是什麽

阿嬷都看得懂的程序码编辑器与开源软件是什麽 我们终於写出了第一支 .html 与 .css 档案了,...

Day27 大眼睛效果

大眼睛效果 教学原文参考:大眼睛效果 这篇文章会介绍使用 GIMP 的扭曲变换工具,将一般人正常的眼...