Files
2025PY/day10/04-for循环.py
2025-05-22 16:50:44 +08:00

24 lines
895 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 一.for循环
# 1.for循环和while循环的区别
# 除了while循环语句外Python同样提供了for循环语句两者能完成的功能基本差不多但仍有一些区别:
# while循环的循环条件是自定义的自行控制循环条件
# for循环是一种"轮询"机制,是对一批内容进行"逐个处理"
# 2.for循环的基础语法
"""
for 临时变量 in 待处理的数据集:
循环体
"""
# 临时变量:用户可以自定义名称,不推荐在循环外使用,故命名临时变量
# 循环体:拿到 "待处理的数据集" 进行逐个处理或者操作
# 待处理数据集:严格来说称之为序列类型
# 序列类型指其内容可以一个个依次取出的一种类型,包括:字符串、列表、元组...
# 案例
str='hello'
for s in str:
print(s)
# 注意 不能直接对某个数字进行处理
# for i in 10:
# print(i)