<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>迭代 on 老张开工了</title>
    <link>/%E8%BF%AD%E4%BB%A3/</link>
    <description>Recent content in 迭代 on 老张开工了</description>
    <generator>Hugo</generator>
    <language>zh-cn</language>
    <lastBuildDate>Fri, 08 May 2026 00:00:00 +0000</lastBuildDate>
    <atom:link href="/%E8%BF%AD%E4%BB%A3/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>循环结构与迭代</title>
      <link>/posts/2026/05/loops/</link>
      <pubDate>Fri, 08 May 2026 00:00:00 +0000</pubDate>
      <guid>/posts/2026/05/loops/</guid>
      <description>条件判断让程序有了决策能力，而循环让程序能够重复执行代码块。循环是编程中最强大的工具之一——它让我们能用几行代码处理成千上万的数据。&#xA;Python 提供两种主要的循环结构：for 循环（用于遍历可迭代对象）和 while 循环（用于条件控制）。&#xA;for 循环 for 循环用于遍历可迭代对象（如列表、元组、字符串、字典、集合等）。&#xA;基本语法 # for 循环的基本结构 fruits = [&amp;#34;苹果&amp;#34;, &amp;#34;香蕉&amp;#34;, &amp;#34;橙子&amp;#34;] for fruit in fruits: print(f&amp;#34;我喜欢吃{fruit}&amp;#34;) # 输出： # 我喜欢吃苹果 # 我喜欢吃香蕉 # 我喜欢吃橙子 遍历不同类型的序列 # 遍历字符串 for char in &amp;#34;Python&amp;#34;: print(char, end=&amp;#34; &amp;#34;) print() # P y t h o n # 遍历元组 for color in (&amp;#34;red&amp;#34;, &amp;#34;green&amp;#34;, &amp;#34;blue&amp;#34;): print(color, end=&amp;#34; &amp;#34;) print() # red green blue # 遍历集合（顺序不确定） for num in {3, 1, 4, 1, 5, 9}: print(num, end=&amp;#34; &amp;#34;) print() # 1 3 4 5 9（自动去重，顺序可能不同） # 遍历字典（默认遍历键） student = {&amp;#34;name&amp;#34;: &amp;#34;张三&amp;#34;, &amp;#34;age&amp;#34;: 20, &amp;#34;score&amp;#34;: 85} for key in student: print(key, end=&amp;#34; &amp;#34;) print() # name age score # 遍历字典的键值对 for key, value in student.</description>
    </item>
  </channel>
</rss>
