Python 中的循环结构主要有两种类型:for 循环和 while 循环。每种循环都有其特定的使用场景,允许你根据需要重复执行代码块。
一、遍历循环for语句
for 循环用于遍历任何序列(如列表、元组或字符串)或其他可迭代对象

(1)for 循环变量 in 遍历对象 :语句块
遍历字符串
for i in 'world':
print(i)

遍历列表
fruits = ["apple", "banana", "cherry"]
for fruit in fruits:
print(fruit)