美文网首页
Python学习笔记0124

Python学习笔记0124

作者: 哈喽小朋友 | 来源:发表于2022-02-23 10:17 被阅读0次

While Loops
...


image.png image.png
image.png
image.png

当用户重复问一个问题时,Python如何检测?
以汽车启动还是停止这个具体问题来说,机器需要知道汽车的状态是开动还是停止,SO需要一个汽车的状态这个变量。
状态是启动还是暂停,这里要用的运算符是:布尔逻辑运算True FALSE
started = False


image.png

For loops>
for 循环语句
集合collection的形式: string-list- range object
[1, 2, 3,....] 输出列表list
range() 输出容器,一个范围范围容器
range(10) 输出0,1,2,。。。9
range(5,10) 输出5,6,7,8,9
range(5,10,2) 这里的2为step,所以 输出为5,7,9

在某一个循环
中,一定要跟对应的循环函数对齐,否则会产生错误:


image.png
image.png

nested LOOP 嵌套循环
用来生成多坐标数组
执行循环的顺序是
先从上至下执行外部循环,一旦进入内部循环,先把内部循环执行完,
再回到外部循环。


image.png image.png

numbers = [5, 2, 5, 2, 2]
for x_count in numbers:
output = ''
for count in range(x_count): #内循环
output += 'x'
print(output)

D:\Aaron\Python\PyCharmProject\Scripts\python.exe D:/Aaron/Python/HelloWorld/app.py
xxxxx
xx
xxxxx
xx
xx

Process finished with exit code 0

作业:找出序列中,最大的数字
numbers = [3, 6, 8, 5, 9, 10]
max = numbers[0]
for number in numbers:
if number > max:
max = number
print(max)

D:\Aaron\Python\PyCharmProject\Scripts\python.exe D:/Aaron/Python/HelloWorld/app.py
10

Process finished with exit code 0

相关文章

网友评论

      本文标题:Python学习笔记0124

      本文链接:https://www.haomeiwen.com/subject/cfwglrtx.html