# Python 八周路线图 · 官方文档学习资料补充

> 基于 [Python 3.12 官方中文文档](https://docs.python.org/zh-cn/3.12/) 整理
> 与 [八周路线图](https://cdn.hellochange.cn/hermes/docs/20260917-python-8week-roadmap.html) 配套使用

---

## 阶段一：Python 基本功（W1-W2）

### Week 1：语法迁移 + 核心数据结构

| 天数 | 路线图内容 | 官方文档对应章节 | 重点说明 |
|:---|:---|:---|:---|
| Day 1 | 环境搭建 + 基本语法 | [2. 使用 Python 的解释器](https://docs.python.org/zh-cn/3.12/tutorial/interpreter.html) | 交互模式、脚本执行 |
| | | [3. Python 速览](https://docs.python.org/zh-cn/3.12/tutorial/introduction.html) | 数字、字符串、列表基础 |
| | | [附录：可执行的 Python 脚本](https://docs.python.org/zh-cn/3.12/tutorial/appendix.html#executable-python-scripts) | `#!/usr/bin/env python3` |
| Day 2 | 变量、类型、控制流 | [4.1-4.5 控制流工具](https://docs.python.org/zh-cn/3.12/tutorial/controlflow.html) | if/elif/else、for、while、break/continue、pass |
| | | [内置类型](https://docs.python.org/zh-cn/3.12/library/stdtypes.html) | int/float/str/bool/list/tuple/dict/set |
| | | [逻辑值检测](https://docs.python.org/zh-cn/3.12/library/stdtypes.html#truth-value-testing) | Python 的 truthy/falsy 与 JS 的差异 |
| Day 3 | 函数定义、参数、lambda | [4.8-4.9 定义函数](https://docs.python.org/zh-cn/3.12/tutorial/controlflow.html#defining-functions) | 默认参数、关键字参数、*args/**kwargs |
| | | [Lambda 表达式](https://docs.python.org/zh-cn/3.12/tutorial/controlflow.html#lambda-expressions) | 与 JS 箭头函数的异同 |
| | | [文档字符串](https://docs.python.org/zh-cn/3.12/tutorial/controlflow.html#documentation-strings) | docstring 规范（Google/Numpy 风格） |
| Day 4 | 列表、元组、集合、字典 | [5. 数据结构](https://docs.python.org/zh-cn/3.12/tutorial/datastructures.html) | 列表推导式、嵌套推导式、循环技巧 |
| | | [5.1.3 列表推导式](https://docs.python.org/zh-cn/3.12/tutorial/datastructures.html#list-comprehensions) | Python 核心特性，必须熟练 |
| | | [内置函数](https://docs.python.org/zh-cn/3.12/library/functions.html) | len/range/enumerate/zip/sorted/map/filter |
| Day 5 | 字符串、格式化、f-string | [7.1 字符串格式化](https://docs.python.org/zh-cn/3.12/tutorial/inputoutput.html#fancier-output-formatting) | f-string、format 规范、% 旧式 |
| | | [文本处理服务](https://docs.python.org/zh-cn/3.12/library/text.html) | string 模块常用方法 |
| | | [PEP 701 f-string 语法](https://docs.python.org/zh-cn/3.12/whatsnew/3.12.html#pep-701-syntactic-formalization-of-f-strings) | 3.12 f-string 增强 |
| Day 6-7 | 周项目：Todo CLI | [6. 模块](https://docs.python.org/zh-cn/3.12/tutorial/modules.html) | import、from...import、__name__ |
| | | [10.1 操作系统接口](https://docs.python.org/zh-cn/3.12/tutorial/stdlib.html#operating-system-interface) | os/sys 模块 |
| | | [7.2 读写文件](https://docs.python.org/zh-cn/3.12/tutorial/inputoutput.html#reading-and-writing-files) | 文件操作、上下文管理器 |

### Week 2：Pythonic 思维 + 错误处理 + 类

| 天数 | 路线图内容 | 官方文档对应章节 | 重点说明 |
|:---|:---|:---|:---|
| Day 8 | 迭代器、生成器 | [9.8 迭代器](https://docs.python.org/zh-cn/3.12/tutorial/classes.html#iterators) | __iter__/__next__ |
| | | [9.9 生成器](https://docs.python.org/zh-cn/3.12/tutorial/classes.html#generators) | yield、生成器表达式 |
| | | [9.10 生成器表达式](https://docs.python.org/zh-cn/3.12/tutorial/classes.html#generator-expressions) | 与列表推导式的区别 |
| | | [itertools](https://docs.python.org/zh-cn/3.12/library/itertools.html) | 迭代器工具函数 |
| Day 9 | 装饰器 | [9.4 补充说明](https://docs.python.org/zh-cn/3.12/tutorial/classes.html#random-remarks) | 闭包、函数作为对象 |
| | | [functools](https://docs.python.org/zh-cn/3.12/library/functools.html) | @wraps、@lru_cache |
| Day 10 | 错误和异常 | [8. 错误和异常](https://docs.python.org/zh-cn/3.12/tutorial/errors.html) | try/except/else/finally |
| | | [内置异常](https://docs.python.org/zh-cn/3.12/library/exceptions.html) | 异常层次结构 |
| | | [用户自定义异常](https://docs.python.org/zh-cn/3.12/tutorial/errors.html#user-defined-exceptions) | 自定义异常类 |
| Day 11 | 类、继承、魔术方法 | [9. 类](https://docs.python.org/zh-cn/3.12/tutorial/classes.html) | 类定义、继承、私有变量 |
| | | [9.3 初探类](https://docs.python.org/zh-cn/3.12/tutorial/classes.html#a-first-look-at-classes) | class 对象、实例对象、方法 |
| | | [9.5 继承](https://docs.python.org/zh-cn/3.12/tutorial/classes.html#inheritance) | 单继承、多重继承、super() |
| | | [特殊方法](https://docs.python.org/zh-cn/3.12/reference/datamodel.html#special-method-names) | __init__/__str__/__repr__/__len__ 等 |
| Day 12 | 类型注解 | [typing 模块](https://docs.python.org/zh-cn/3.12/library/typing.html) | List/Dict/Optional/Union/Callable |
| | | [PEP 695 类型参数语法](https://docs.python.org/zh-cn/3.12/whatsnew/3.12.html#pep-695-type-parameter-syntax) | 3.12 泛型新语法 |
| | | [PEP 692 TypedDict](https://docs.python.org/zh-cn/3.12/whatsnew/3.12.html#pep-692-using-typeddict-for-more-precise-kwargs-typing) | 精确 kwargs 类型 |
| | | [PEP 698 @override](https://docs.python.org/zh-cn/3.12/whatsnew/3.12.html#pep-698-override-decorator-for-static-typing) | 静态类型检查装饰器 |
| Day 13 | 虚拟环境 + 包管理 | [12. 虚拟环境和包](https://docs.python.org/zh-cn/3.12/tutorial/venv.html) | venv、pip 基础 |
| | | [软件打包和分发](https://docs.python.org/zh-cn/3.12/library/distribution.html) | pyproject.toml 结构 |
| | | uv 官方文档 | 替代 pip，更快 |
| Day 14 | 周项目：Todo CLI 完整版 | [10.3 命令行参数](https://docs.python.org/zh-cn/3.12/tutorial/stdlib.html#command-line-arguments) | argparse |
| | | [10.5 字符串模式匹配](https://docs.python.org/zh-cn/3.12/tutorial/stdlib.html#string-pattern-matching) | re 正则 |
| | | [10.8 日期和时间](https://docs.python.org/zh-cn/3.12/tutorial/stdlib.html#dates-and-times) | datetime |

---

## 阶段二：FastAPI 后端（W3-W5）

### Week 3：FastAPI 入门 + 数据库

| 天数 | 路线图内容 | 官方文档对应章节 | 重点说明 |
|:---|:---|:---|:---|
| Day 15 | FastAPI 第一个 API | [FastAPI 官方文档](https://fastapi.tiangolo.com/zh/) | 路径操作、请求/响应模型 |
| | | [Pydantic 文档](https://docs.pydantic.dev/latest/) | BaseModel、Field、验证器 |
| | | [7.1.3 手动格式化字符串](https://docs.python.org/zh-cn/3.12/tutorial/inputoutput.html#manual-string-formatting) | 字符串模板 |
| Day 16 | REST API 设计 | [FastAPI 路径参数](https://fastapi.tiangolo.com/zh/tutorial/path-params/) | 路径/查询参数 |
| | | [FastAPI 请求体](https://fastapi.tiangolo.com/zh/tutorial/body/) | Pydantic 模型 |
| | | [FastAPI 响应模型](https://fastapi.tiangolo.com/zh/tutorial/response-model/) | response_model |
| Day 17 | 数据库 SQLAlchemy | [SQLAlchemy 2.0 文档](https://docs.sqlalchemy.org/en/20/) | 引擎、会话、模型、CRUD |
| | | [10.12 自带电池](https://docs.python.org/zh-cn/3.12/tutorial/stdlib.html#batteries-included) | sqlite3 模块 |
| | | [数据持久化](https://docs.python.org/zh-cn/3.12/library/persistence.html) | dbm、shelve |
| Day 18 | 数据库迁移 Alembic | [Alembic 文档](https://alembic.sqlalchemy.org/) | 迁移脚本、版本管理 |
| Day 19 | 用户认证 JWT | [FastAPI 安全](https://fastapi.tiangolo.com/zh/tutorial/security/) | OAuth2、JWT、密码哈希 |
| | | [10.4 错误输出重定向](https://docs.python.org/zh-cn/3.12/tutorial/stdlib.html#error-output-redirection-and-program-termination) | sys.stderr、sys.exit |
| Day 20-21 | 周项目：Todo API | [FastAPI 依赖注入](https://fastapi.tiangolo.com/zh/tutorial/dependencies/) | Depends |
| | | [FastAPI 中间件](https://fastapi.tiangolo.com/zh/tutorial/middleware/) | CORS、GZip |
| | | [logging 模块](https://docs.python.org/zh-cn/3.12/library/logging.html) | 日志记录 |

### Week 4：异步 + 外部调用 + Docker

| 天数 | 路线图内容 | 官方文档对应章节 | 重点说明 |
|:---|:---|:---|:---|
| Day 22 | asyncio 异步编程 | [asyncio 模块](https://docs.python.org/zh-cn/3.12/library/asyncio.html) | 事件循环、协程、任务 |
| | | [并发执行](https://docs.python.org/zh-cn/3.12/library/concurrency.html) | threading/multiprocessing/asyncio 对比 |
| | | [PEP 684 Per-Interpreter GIL](https://docs.python.org/zh-cn/3.12/whatsnew/3.12.html#pep-684-a-per-interpreter-gil) | 3.12 GIL 改进 |
| | | [10.4 多线程](https://docs.python.org/zh-cn/3.12/tutorial/stdlib2.html#multi-threading) | threading 基础 |
| Day 23 | httpx 异步 HTTP | [httpx 文档](https://www.python-httpx.org/) | 异步客户端、连接池 |
| | | [urllib.request](https://docs.python.org/zh-cn/3.12/library/urllib.request.html) | 标准库 HTTP（了解） |
| | | [json 模块](https://docs.python.org/zh-cn/3.12/library/json.html) | JSON 编解码 |
| Day 24 | 文件上传下载 | [FastAPI 文件](https://fastapi.tiangolo.com/zh/tutorial/request-files/) | UploadFile、File |
| | | [10.9 数据压缩](https://docs.python.org/zh-cn/3.12/tutorial/stdlib.html#data-compression) | gzip、zipfile |
| | | [文件和目录访问](https://docs.python.org/zh-cn/3.12/library/filesys.html) | pathlib、shutil |
| Day 25 | Docker 容器化 | [Docker 官方文档](https://docs.docker.com/) | Dockerfile、docker-compose |
| | | [10.2 文件通配符](https://docs.python.org/zh-cn/3.12/tutorial/stdlib.html#file-wildcards) | glob |
| Day 26-28 | 周项目：Todo API 完整版 | [FastAPI 测试](https://fastapi.tiangolo.com/zh/tutorial/testing/) | TestClient |
| | | [pytest 文档](https://docs.pytest.org/) | fixture、参数化、标记 |
| | | [11.1 格式化输出](https://docs.python.org/zh-cn/3.12/tutorial/stdlib2.html#output-formatting) | pprint、textwrap |
| | | [10.10 性能测量](https://docs.python.org/zh-cn/3.12/tutorial/stdlib.html#performance-measurement) | timeit、profile |

### Week 5：FastAPI 进阶 + LLM API 接入

| 天数 | 路线图内容 | 官方文档对应章节 | 重点说明 |
|:---|:---|:---|:---|
| Day 29 | LLM API 调用 | [Anthropic Python SDK](https://docs.anthropic.com/en/api/client-sdks) | Messages API、流式输出 |
| | | [OpenAI Python SDK](https://github.com/openai/openai-python) | Chat Completions |
| | | [SSE 流式输出](https://fastapi.tiangolo.com/zh/advanced/custom-response/#streamingresponse) | StreamingResponse |
| Day 30 | Pydantic 结构化输出 | [instructor 文档](https://jxnl.github.io/instructor/) | 结构化输出、重试 |
| | | [Pydantic 验证器](https://docs.pydantic.dev/latest/concepts/validators/) | @field_validator |
| Day 31 | Prompt 工程 | [Anthropic Prompt 工程](https://docs.anthropic.com/en/docs/build-with-claude/prompt-engineering/overview) | system prompt、few-shot |
| Day 32 | 多轮对话 + 上下文管理 | [FastAPI WebSocket](https://fastapi.tiangolo.com/zh/advanced/websockets/) | 实时通信 |
| | | [11.5 日志记录](https://docs.python.org/zh-cn/3.12/tutorial/stdlib2.html#logging) | logging 高级用法 |
| Day 33 | 并发调用 | [asyncio.gather](https://docs.python.org/zh-cn/3.12/library/asyncio-task.html#asyncio.gather) | 并发协程 |
| | | [asyncio 信号量](https://docs.python.org/zh-cn/3.12/library/asyncio-sync.html#asyncio.Semaphore) | 限流 |
| Day 34-35 | 周项目：AI 聊天 API | [FastAPI 后台任务](https://fastapi.tiangolo.com/zh/tutorial/background-tasks/) | BackgroundTasks |

---

## 阶段三：AI/Agent（W5-W8）

### Week 6：RAG 和工具调用

| 天数 | 路线图内容 | 官方文档对应章节 | 重点说明 |
|:---|:---|:---|:---|
| Day 36 | Embedding | [OpenAI Embedding](https://platform.openai.com/docs/guides/embeddings) | 文本向量化 |
| | | [sentence-transformers](https://www.sbert.net/) | 本地 embedding 模型 |
| | | [array 模块](https://docs.python.org/zh-cn/3.12/library/array.html) | 数值数组 |
| Day 37 | 向量数据库 | [ChromaDB 文档](https://docs.trychroma.com/) | 本地向量库 |
| | | [sqlite3 模块](https://docs.python.org/zh-cn/3.12/library/sqlite3.html) | 轻量存储 |
| Day 38 | RAG 完整流程 | [LangChain RAG](https://python.langchain.com/docs/tutorials/rag/) | 检索增强生成 |
| | | [7.2.1 文件对象的方法](https://docs.python.org/zh-cn/3.12/tutorial/inputoutput.html#methods-of-file-objects) | 文件读取 |
| Day 39 | Function Calling | [Anthropic Tool Use](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/overview) | 工具定义、调用 |
| | | [OpenAI Function Calling](https://platform.openai.com/docs/guides/function-calling) | 函数调用 |
| Day 40 | 多工具组合 | [inspect 模块](https://docs.python.org/zh-cn/3.12/library/inspect.html) | 运行时检查 |
| | | [PEP 669 低影响监控](https://docs.python.org/zh-cn/3.12/whatsnew/3.12.html#pep-669-low-impact-monitoring-for-cpython) | 3.12 监控 API |
| Day 41-42 | 周项目：RAG + 工具 Agent | [11.7 用于操作列表的工具](https://docs.python.org/zh-cn/3.12/tutorial/stdlib2.html#tools-for-working-with-lists) | heapq、bisect |

### Week 7：Agent 框架和高级模式

| 天数 | 路线图内容 | 官方文档对应章节 | 重点说明 |
|:---|:---|:---|:---|
| Day 43 | 框架选型 | [LangGraph 文档](https://langchain-ai.github.io/langgraph/) | Agent 工作流 |
| | | [CrewAI 文档](https://docs.crewai.com/) | 多 Agent 协作 |
| | | [9.1 名称和对象](https://docs.python.org/zh-cn/3.12/tutorial/classes.html#a-word-about-names-and-objects) | 可变/不可变对象 |
| Day 44 | ReAct 模式 | [ReAct 论文](https://arxiv.org/abs/2210.03629) | 推理+行动 |
| | | [enum 模块](https://docs.python.org/zh-cn/3.12/library/enum.html) | 枚举类型 |
| Day 45 | 记忆和状态 | [dataclasses](https://docs.python.org/zh-cn/3.12/library/dataclasses.html) | 数据类 |
| | | [pickle 模块](https://docs.python.org/zh-cn/3.12/library/pickle.html) | 对象序列化 |
| Day 46 | 规划和分解 | [11.2 模板](https://docs.python.org/zh-cn/3.12/tutorial/stdlib2.html#templating) | string.Template |
| | | [ast 模块](https://docs.python.org/zh-cn/3.12/library/ast.html) | 抽象语法树 |
| Day 47 | 评估和调试 | [pdb 调试器](https://docs.python.org/zh-cn/3.12/library/pdb.html) | 断点调试 |
| | | [traceback 模块](https://docs.python.org/zh-cn/3.12/library/traceback.html) | 异常追踪 |
| | | [LangSmith](https://docs.smith.langchain.com/) | LLM 应用追踪 |
| Day 48-49 | 周项目：完整 Agent | [WebSocket 实时通信](https://fastapi.tiangolo.com/zh/advanced/websockets/) | 前端聊天界面 |

### Week 8：毕业项目

| 项目选项 | 涉及官方文档模块 |
|:---|:---|
| A. AI 助手 | FastAPI + StreamingResponse + WebSocket + asyncio + chromadb + instructor |
| B. 自动化 Agent | [sched 模块](https://docs.python.org/zh-cn/3.12/library/sched.html) + httpx + sqlite3 + logging |
| C. 代码助手 | [ast](https://docs.python.org/zh-cn/3.12/library/ast.html) + [tokenize](https://docs.python.org/zh-cn/3.12/library/tokenize.html) + RAG + pathlib |

---

## 通用参考（随时查阅）

| 类别 | 链接 | 用途 |
|:---|:---|:---|
| **官方教程** | [Python 教程](https://docs.python.org/zh-cn/3.12/tutorial/index.html) | 系统学习语法 |
| **标准库** | [Python 标准库](https://docs.python.org/zh-cn/3.12/library/index.html) | 内置模块速查 |
| **内置函数** | [内置函数](https://docs.python.org/zh-cn/3.12/library/functions.html) | len/range/zip 等 |
| **内置类型** | [内置类型](https://docs.python.org/zh-cn/3.12/library/stdtypes.html) | str/list/dict/set |
| **内置异常** | [内置异常](https://docs.python.org/zh-cn/3.12/library/exceptions.html) | 异常层次结构 |
| **语言参考** | [Python 语言参考](https://docs.python.org/zh-cn/3.12/reference/index.html) | 语法规范 |
| **What's New** | [Python 3.12 新特性](https://docs.python.org/zh-cn/3.12/whatsnew/3.12.html) | 3.12 变更 |
| **PEP 8** | [编码风格](https://docs.python.org/zh-cn/3.12/tutorial/controlflow.html#intermezzo-coding-style) | 代码规范 |
| **Glossary** | [术语表](https://docs.python.org/zh-cn/3.12/glossary.html) | 概念速查 |

---

## 前端开发者特别注意的 Python 差异

| 概念 | JavaScript | Python | 官方文档 |
|:---|:---|:---|:---|
| 空值 | `null` / `undefined` | `None` | [内置常量](https://docs.python.org/zh-cn/3.12/library/constants.html) |
| 数组 | `Array` (动态) | `list` (有序) / `tuple` (不可变) | [序列类型](https://docs.python.org/zh-cn/3.12/library/stdtypes.html#sequence-types-list-tuple-range) |
| 对象 | `Object` / `Map` | `dict` | [映射类型](https://docs.python.org/zh-cn/3.12/library/stdtypes.html#mapping-types-dict) |
| 集合 | `Set` | `set` / `frozenset` | [集合类型](https://docs.python.org/zh-cn/3.12/library/stdtypes.html#set-types-set-frozenset) |
| 字符串模板 | 模板字面量 | f-string | [格式化字符串字面值](https://docs.python.org/zh-cn/3.12/reference/lexical_analysis.html#f-strings) |
| 解构 | `const {a, b} = obj` | `a, b = obj.values()` / 解包 | [解包实参列表](https://docs.python.org/zh-cn/3.12/tutorial/controlflow.html#unpacking-argument-lists) |
| 展开 | `...spread` | `*args` / `**kwargs` | [任意实参列表](https://docs.python.org/zh-cn/3.12/tutorial/controlflow.html#arbitrary-argument-lists) |
| 异步 | `Promise` / `async-await` | `asyncio` / `async-await` | [asyncio](https://docs.python.org/zh-cn/3.12/library/asyncio.html) |
| 类 | `class` / `prototype` | `class` / 继承 | [类](https://docs.python.org/zh-cn/3.12/tutorial/classes.html) |
| 模块 | `import/export` | `import/from...import` | [模块](https://docs.python.org/zh-cn/3.12/tutorial/modules.html) |
| 包管理 | npm/pnpm | pip/uv | [虚拟环境和包](https://docs.python.org/zh-cn/3.12/tutorial/venv.html) |
| 类型检查 | TypeScript | 类型注解 + pyright | [typing](https://docs.python.org/zh-cn/3.12/library/typing.html) |

---

> 生成时间：2026-09-18
> 配套路线图：[八周路线图](https://cdn.hellochange.cn/hermes/docs/20260917-python-8week-roadmap.html)
