From 18a77736c0098c3a105756eae1ad79d0793ff3d7 Mon Sep 17 00:00:00 2001 From: redbotu Date: Mon, 25 May 2026 22:23:20 +0800 Subject: [PATCH] =?UTF-8?q?docs:=20=E6=B7=BB=E5=8A=A0=20Java=20=E5=BC=80?= =?UTF-8?q?=E5=8F=91=E8=80=85=20Python=20=E9=80=9F=E6=9F=A5=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- langgraph-tutorial/Python速查表.md | 120 +++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 langgraph-tutorial/Python速查表.md diff --git a/langgraph-tutorial/Python速查表.md b/langgraph-tutorial/Python速查表.md new file mode 100644 index 0000000..d62edab --- /dev/null +++ b/langgraph-tutorial/Python速查表.md @@ -0,0 +1,120 @@ +# Java 开发者 Python 速查表 + +## 基础语法对比 + +| 概念 | Java | Python | +|------|------|--------| +| 打印 | `System.out.println("hi");` | `print("hi")` | +| 条件 | `if (x > 0) { ... }` | `if x > 0: ...` | +| 循环 | `for (String s : list) { ... }` | `for s in list: ...` | +| 方法 | `public String hello() { return "hi"; }` | `def hello() -> str: return "hi"` | +| 类 | `public class Foo { String bar; }` | `class Foo: bar: str` | +| 导入 | `import java.util.List;` | `from typing import List` | + +## 数据类型对比 + +| Java | Python | 说明 | +|------|--------|------| +| `String` | `str` | 字符串 | +| `int` | `int` | 整数 | +| `double` | `float` | 浮点数 | +| `boolean` | `bool` | 布尔值 | +| `List` | `list` | 列表 | +| `Map` | `dict` | 字典 | +| `null` | `None` | 空值 | +| `true/false` | `True/False` | 布尔值 | + +## 常用操作对比 + +### 字符串 +```java +// Java +String s = "hello"; +s.length(); // 长度 +s.toUpperCase(); // 大写 +s.contains("ll"); // 包含 +s.replace("l", "r"); // 替换 +String.format("%s %d", s, 42); // 格式化 +``` + +```python +# Python +s = "hello" +len(s) # 长度 +s.upper() # 大写 +"ll" in s # 包含 +s.replace("l", "r") # 替换 +f"{s} {42}" # 格式化(f-string) +``` + +### 集合 +```java +// Java +List list = new ArrayList<>(); +list.add("a"); +list.get(0); +list.size(); + +Map map = new HashMap<>(); +map.put("key", 1); +map.get("key"); +map.containsKey("key"); +``` + +```python +# Python +list = [] +list.append("a") +list[0] +len(list) + +map = {} +map["key"] = 1 +map.get("key") +"key" in map +``` + +## Python 特有概念 + +### 缩进代替花括号 +```python +# Python 用缩进表示代码块 +if x > 0: + print("正数") # 必须缩进 +else: + print("非正数") +``` + +### 类型提示(可选) +```python +# Python 类型提示只是给编辑器看的,运行时不检查 +def hello(name: str) -> str: + return f"Hello, {name}" + +# 这样写也可以运行 +def hello(name): + return "Hello, " + name +``` + +### 字典推导 +```python +# 创建字典 +d = {"key": "value"} + +# 遍历 +for k, v in d.items(): + print(k, v) + +# 安全访问 +d.get("key") # 不存在返回 None +d.get("key", "默认") # 不存在返回默认值 +``` + +## LangGraph 核心概念 + +| 概念 | 说明 | Java 类比 | +|------|------|----------| +| State | 节点间传递的数据 | DTO/Entity 类 | +| Node | 处理函数 | Service 方法 | +| Edge | 节点连接 | 流程控制 | +| Graph | 有向图 | 工作流引擎 | \ No newline at end of file