[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"$fN02eqgk7OAB2Iq267txYlnOhYukmRlEmfMi48inKBoA":3,"$fJU-4tot_gC5fDkujNeoE-cGsdMy5V_KcdUXLuAnTFgw":15,"$fzD6BR0ukB0ftP0SiCTWpipBMKEmy5uBPC4w6feKYx00":423},{"slug":4,"title":5,"description":6,"content":7,"content_html":8,"pub_date":9,"tags":10,"draft":14},"python-basics-quick-start","Python 快速上手：写给有编程基础的人","已经会其他语言，想快速掌握 Python 的语法特性和思维方式，这篇是捷径。","# Python 快速上手：写给有编程基础的人\n\n已经会 Java、Go、C++ 或者 JavaScript？这篇文章帮你用最短时间掌握 Python 的语法特性和思维方式，跳过基础概念，直接聚焦\"和其他语言不一样的地方\"。\n\n---\n\n## Python vs 其他语言的关键区别\n\n### 缩进即结构\nPython 用缩进代替 `{}`，不是风格问题，是语法要求：\n\n```python\nif x > 0:\n    print(\"positive\")  # 必须缩进\n    x -= 1\nprint(\"done\")           # 在 if 外面\n```\n\n### 动态类型\n```python\nx = 42        # int\nx = \"hello\"   # 现在是 str，完全合法\nx = [1, 2, 3] # 现在是 list\n```\n\n类型提示（type hints）是可选的，不影响运行时：\n```python\ndef greet(name: str) -> str:\n    return f\"Hello, {name}\"\n```\n\n### GIL（Global Interpreter Lock）\nCPython 的多线程受 GIL 限制，CPU 密集型任务用 `multiprocessing` 或 `concurrent.futures.ProcessPoolExecutor`，IO 密集型用 `asyncio` 或线程。\n\n---\n\n## 变量与基础类型\n\n```python\n# 基础类型\nx: int = 42\npi: float = 3.14\nname: str = \"Alice\"\nflag: bool = True\nnothing: None = None\ndata: bytes = b\"hello\"\n\n# 类型转换\nint(\"42\")        # 42\nfloat(\"3.14\")    # 3.14\nstr(42)          # \"42\"\nbool(0)          # False（0, \"\", [], {}, None 都是假值）\nlist(\"abc\")      # ['a', 'b', 'c']\n```\n\n**Python 的真假值（Falsy values）**：`0`、`0.0`、`\"\"`、`[]`、`{}`、`()`、`set()`、`None`、`False`。\n\n---\n\n## 字符串操作\n\n### f-string（首选）\n```python\nname = \"World\"\nage = 25\nprint(f\"Hello, {name}! Age: {age}\")\nprint(f\"{3.14159:.2f}\")     # 格式化：3.14\nprint(f\"{1000000:,}\")       # 千分位：1,000,000\nprint(f\"{'left':\u003C10}|\")     # 左对齐\nprint(f\"{'right':>10}|\")    # 右对齐\n```\n\n### 切片\n```python\ns = \"Hello, World!\"\ns[0]      # H\ns[-1]     # !\ns[7:]     # World!\ns[:5]     # Hello\ns[::2]    # Hlo ol!（每隔一个）\ns[::-1]   # !dlroW ,olleH（反转）\n```\n\n### 常用方法\n```python\n\"  hello  \".strip()          # hello\n\"hello world\".split()        # ['hello', 'world']\n\", \".join([\"a\", \"b\", \"c\"])   # a, b, c\n\"Hello\".lower()              # hello\n\"hello\".upper()              # HELLO\n\"hello world\".replace(\"o\", \"0\")  # hell0 w0rld\n\"hello\".startswith(\"he\")    # True\n\"hello\".find(\"ll\")           # 2\n```\n\n---\n\n## 列表\n\n```python\nnums = [1, 2, 3, 4, 5]\n\n# 切片\nnums[1:3]    # [2, 3]\nnums[::-1]   # [5, 4, 3, 2, 1]\n\n# 常用方法\nnums.append(6)           # 尾部追加，O(1)\nnums.extend([7, 8])      # 追加多个\nnums.insert(0, 0)        # 头部插入，O(n) 慎用\nnums.pop()               # 移除尾部，O(1)\nnums.pop(0)              # 移除头部，O(n) 慎用\nnums.remove(3)           # 移除第一个值为 3 的元素\nnums.index(4)            # 找到元素的下标\nnums.sort()              # 原地排序\nsorted(nums)             # 返回新列表\nnums.sort(reverse=True)  # 降序\nnums.sort(key=lambda x: -x)  # 自定义排序\n```\n\n### 列表推导式\n```python\n# 基础\nsquares = [x**2 for x in range(10)]\n\n# 带条件\nevens = [x for x in range(20) if x % 2 == 0]\n\n# 双重循环\npairs = [(x, y) for x in [1,2,3] for y in [4,5,6]]\n\n# 对比 Java：\n# List\u003CInteger> squares = IntStream.range(0, 10)\n#     .map(x -> x * x).boxed().collect(Collectors.toList());\n```\n\n---\n\n## 字典\n\n```python\nd = {\"name\": \"Alice\", \"age\": 25}\n\n# 访问\nd[\"name\"]           # Alice，不存在时 KeyError\nd.get(\"email\")      # None，不存在时返回 None\nd.get(\"email\", \"\")  # 指定默认值\n\n# 修改\nd[\"city\"] = \"Beijing\"\nd.update({\"age\": 26, \"job\": \"dev\"})\n\n# 遍历\nfor k, v in d.items():\n    print(f\"{k}: {v}\")\n\n# 字典推导式\nsquared = {k: v**2 for k, v in {\"a\": 1, \"b\": 2}.items()}\n\n# 合并（Python 3.9+）\nmerged = {\"a\": 1} | {\"b\": 2}   # {'a': 1, 'b': 2}\nd1 = {\"a\": 1}\nd1 |= {\"b\": 2}                  # 原地合并\n\n# 旧方法（兼容 3.8）\nmerged = {**d1, **d2}\n```\n\n---\n\n## 元组\n\n```python\npoint = (3, 4)\nx, y = point          # 解包\na, *rest = (1, 2, 3, 4)  # a=1, rest=[2, 3, 4]\n\n# 元组可作 dict key（不可变）\ncache = {}\ncache[(0, 0)] = \"origin\"\n\n# 单元素元组\nsingle = (42,)   # 注意逗号！(42) 只是括号，不是元组\n\n# namedtuple（结构化）\nfrom collections import namedtuple\nPoint = namedtuple(\"Point\", [\"x\", \"y\"])\np = Point(3, 4)\nprint(p.x, p.y)  # 3 4\n```\n\n---\n\n## 集合\n\n```python\ns1 = {1, 2, 3, 4}\ns2 = {3, 4, 5, 6}\n\ns1 & s2    # 交集：{3, 4}\ns1 | s2    # 并集：{1, 2, 3, 4, 5, 6}\ns1 - s2    # 差集：{1, 2}\ns1 ^ s2    # 对称差：{1, 2, 5, 6}\n\n# 去重\nunique = list(set([1, 2, 2, 3, 3, 3]))  # [1, 2, 3]\n\n# 成员检测 O(1)\nprint(3 in s1)   # True\n\n# frozenset（不可变，可作 dict key）\nfs = frozenset([1, 2, 3])\n```\n\n---\n\n## 条件与循环\n\n```python\n# 三元表达式（类比 Java\u002FJS 的 ? :）\nresult = \"yes\" if condition else \"no\"\n\n# for-else（Python 特有！其他语言没有）\nfor item in items:\n    if item == target:\n        break\nelse:\n    # 只有循环正常结束（没有 break）才执行\n    print(\"not found\")\n\n# enumerate（带下标的 for）\nfor i, v in enumerate([\"a\", \"b\", \"c\"]):\n    print(i, v)  # 0 a \u002F 1 b \u002F 2 c\n\n# zip（同步遍历多个序列）\nfor a, b in zip([1, 2, 3], [\"x\", \"y\", \"z\"]):\n    print(a, b)\n```\n\n---\n\n## 函数\n\n```python\n# 默认参数\ndef connect(host, port=5432, timeout=30):\n    pass\n\n# 关键字参数（顺序无关）\nconnect(host=\"localhost\", timeout=10, port=3306)\n\n# *args 和 **kwargs\ndef log(*args, **kwargs):\n    print(args)    # tuple\n    print(kwargs)  # dict\n\nlog(1, 2, 3, level=\"info\", tag=\"debug\")\n\n# 仅关键字参数（* 之后的参数）\ndef func(a, b, *, key_only):\n    pass\nfunc(1, 2, key_only=3)   # OK\n\n# lambda（适合简单的一次性函数）\nsquare = lambda x: x**2\nnums.sort(key=lambda x: x[1])   # 按第二个元素排序\n```\n\n---\n\n## 解包技巧\n\n```python\n# 交换变量（Python 独有的优雅）\na, b = b, a\n\n# 扩展解包\nfirst, *middle, last = [1, 2, 3, 4, 5]\n# first=1, middle=[2,3,4], last=5\n\n# _ 作占位符\n_, important, _ = (1, 2, 3)\n\n# 函数参数解包\nargs = (1, 2, 3)\nfunc(*args)          # 等同于 func(1, 2, 3)\n\nkwargs = {\"a\": 1, \"b\": 2}\nfunc(**kwargs)       # 等同于 func(a=1, b=2)\n```\n\n---\n\n## with 语句与上下文管理器\n\n```python\n# 文件操作（自动关闭）\nwith open(\"file.txt\", \"r\", encoding=\"utf-8\") as f:\n    content = f.read()\n# 退出 with 块后文件自动关闭，即使发生异常\n\n# 多个上下文管理器\nwith open(\"input.txt\") as fin, open(\"output.txt\", \"w\") as fout:\n    fout.write(fin.read())\n\n# 自定义上下文管理器\nfrom contextlib import contextmanager\n\n@contextmanager\ndef timer():\n    import time\n    start = time.time()\n    yield\n    print(f\"Elapsed: {time.time() - start:.3f}s\")\n\nwith timer():\n    expensive_operation()\n```\n\n---\n\n## 推导式全家桶\n\n```python\ndata = range(10)\n\n# list comprehension\nsquares = [x**2 for x in data]\n\n# dict comprehension\nsquare_map = {x: x**2 for x in data}\n\n# set comprehension\nunique_mods = {x % 3 for x in data}\n\n# generator expression（惰性求值，省内存）\ngen = (x**2 for x in data)\ntotal = sum(x**2 for x in data)    # 直接传生成器表达式\n\n# 嵌套推导式\nmatrix = [[1,2,3],[4,5,6],[7,8,9]]\nflat = [x for row in matrix for x in row]\n```\n\n---\n\n## 常用标准库速览\n\n```python\n# pathlib：现代文件路径操作（替代 os.path）\nfrom pathlib import Path\np = Path(\"\u002Fhome\u002Fuser\u002Fdocs\")\np \u002F \"file.txt\"           # 路径拼接\np.exists()               # 是否存在\np.glob(\"*.py\")           # 通配符\np.read_text()            # 读取文件\np.write_text(\"hello\")    # 写入文件\n\n# json\nimport json\ntext = json.dumps({\"key\": \"value\"}, ensure_ascii=False, indent=2)\ndata = json.loads(text)\n\n# re（正则）\nimport re\nm = re.search(r\"\\d+\", \"abc123def\")\nm.group()   # 123\nre.findall(r\"\\w+\", \"hello world\")   # ['hello', 'world']\n\n# datetime\nfrom datetime import datetime, timedelta\nnow = datetime.now()\ntomorrow = now + timedelta(days=1)\nnow.strftime(\"%Y-%m-%d %H:%M:%S\")\ndatetime.strptime(\"2026-01-01\", \"%Y-%m-%d\")\n\n# collections\nfrom collections import Counter, defaultdict, deque\nCounter(\"abracadabra\")    # {'a': 5, 'b': 2, ...}\ndd = defaultdict(list)\ndd[\"key\"].append(1)       # 自动初始化\n```\n\n---\n\n## 快速对比：Python vs 其他语言\n\n| 特性 | Python | Java\u002FC++ | JavaScript |\n|------|--------|----------|------------|\n| 变量声明 | `x = 1` | `int x = 1;` | `let x = 1` |\n| 字符串插值 | `f\"{x}\"` | `String.format()` | `` `${x}` `` |\n| 列表\u002F数组 | `list` | `ArrayList` | `Array` |\n| 字典\u002FMap | `dict` | `HashMap` | `Object\u002FMap` |\n| 空值 | `None` | `null` | `null\u002Fundefined` |\n| 注释 | `# ...` | `\u002F\u002F ...` | `\u002F\u002F ...` |\n\nPython 的哲学：**显式优于隐式，可读性最重要**（The Zen of Python）。\n","\u003Ch1>Python 快速上手：写给有编程基础的人\u003C\u002Fh1>\n\u003Cp>已经会 Java、Go、C++ 或者 JavaScript？这篇文章帮你用最短时间掌握 Python 的语法特性和思维方式，跳过基础概念，直接聚焦&quot;和其他语言不一样的地方&quot;。\u003C\u002Fp>\n\u003Chr>\n\u003Ch2 id=\"python-vs-其他语言的关键区别\">Python vs 其他语言的关键区别\u003C\u002Fh2>\n\u003Ch3 id=\"缩进即结构\">缩进即结构\u003C\u002Fh3>\n\u003Cp>Python 用缩进代替 \u003Ccode>{}\u003C\u002Fcode>，不是风格问题，是语法要求：\u003C\u002Fp>\n\u003Cpre>\u003Ccode class=\"language-python\">if x &gt; 0:\n    print(&quot;positive&quot;)  # 必须缩进\n    x -= 1\nprint(&quot;done&quot;)           # 在 if 外面\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Ch3 id=\"动态类型\">动态类型\u003C\u002Fh3>\n\u003Cpre>\u003Ccode class=\"language-python\">x = 42        # int\nx = &quot;hello&quot;   # 现在是 str，完全合法\nx = [1, 2, 3] # 现在是 list\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>类型提示（type hints）是可选的，不影响运行时：\u003C\u002Fp>\n\u003Cpre>\u003Ccode class=\"language-python\">def greet(name: str) -&gt; str:\n    return f&quot;Hello, {name}&quot;\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Ch3 id=\"gil-global-interpreter-lock\">GIL（Global Interpreter Lock）\u003C\u002Fh3>\n\u003Cp>CPython 的多线程受 GIL 限制，CPU 密集型任务用 \u003Ccode>multiprocessing\u003C\u002Fcode> 或 \u003Ccode>concurrent.futures.ProcessPoolExecutor\u003C\u002Fcode>，IO 密集型用 \u003Ccode>asyncio\u003C\u002Fcode> 或线程。\u003C\u002Fp>\n\u003Chr>\n\u003Ch2 id=\"变量与基础类型\">变量与基础类型\u003C\u002Fh2>\n\u003Cpre>\u003Ccode class=\"language-python\"># 基础类型\nx: int = 42\npi: float = 3.14\nname: str = &quot;Alice&quot;\nflag: bool = True\nnothing: None = None\ndata: bytes = b&quot;hello&quot;\n\n# 类型转换\nint(&quot;42&quot;)        # 42\nfloat(&quot;3.14&quot;)    # 3.14\nstr(42)          # &quot;42&quot;\nbool(0)          # False（0, &quot;&quot;, [], {}, None 都是假值）\nlist(&quot;abc&quot;)      # ['a', 'b', 'c']\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>\u003Cstrong>Python 的真假值（Falsy values）\u003C\u002Fstrong>：\u003Ccode>0\u003C\u002Fcode>、\u003Ccode>0.0\u003C\u002Fcode>、\u003Ccode>&quot;&quot;\u003C\u002Fcode>、\u003Ccode>[]\u003C\u002Fcode>、\u003Ccode>{}\u003C\u002Fcode>、\u003Ccode>()\u003C\u002Fcode>、\u003Ccode>set()\u003C\u002Fcode>、\u003Ccode>None\u003C\u002Fcode>、\u003Ccode>False\u003C\u002Fcode>。\u003C\u002Fp>\n\u003Chr>\n\u003Ch2 id=\"字符串操作\">字符串操作\u003C\u002Fh2>\n\u003Ch3 id=\"f-string-首选\">f-string（首选）\u003C\u002Fh3>\n\u003Cpre>\u003Ccode class=\"language-python\">name = &quot;World&quot;\nage = 25\nprint(f&quot;Hello, {name}! Age: {age}&quot;)\nprint(f&quot;{3.14159:.2f}&quot;)     # 格式化：3.14\nprint(f&quot;{1000000:,}&quot;)       # 千分位：1,000,000\nprint(f&quot;{'left':&lt;10}|&quot;)     # 左对齐\nprint(f&quot;{'right':&gt;10}|&quot;)    # 右对齐\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Ch3 id=\"切片\">切片\u003C\u002Fh3>\n\u003Cpre>\u003Ccode class=\"language-python\">s = &quot;Hello, World!&quot;\ns[0]      # H\ns[-1]     # !\ns[7:]     # World!\ns[:5]     # Hello\ns[::2]    # Hlo ol!（每隔一个）\ns[::-1]   # !dlroW ,olleH（反转）\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Ch3 id=\"常用方法\">常用方法\u003C\u002Fh3>\n\u003Cpre>\u003Ccode class=\"language-python\">&quot;  hello  &quot;.strip()          # hello\n&quot;hello world&quot;.split()        # ['hello', 'world']\n&quot;, &quot;.join([&quot;a&quot;, &quot;b&quot;, &quot;c&quot;])   # a, b, c\n&quot;Hello&quot;.lower()              # hello\n&quot;hello&quot;.upper()              # HELLO\n&quot;hello world&quot;.replace(&quot;o&quot;, &quot;0&quot;)  # hell0 w0rld\n&quot;hello&quot;.startswith(&quot;he&quot;)    # True\n&quot;hello&quot;.find(&quot;ll&quot;)           # 2\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Chr>\n\u003Ch2 id=\"列表\">列表\u003C\u002Fh2>\n\u003Cpre>\u003Ccode class=\"language-python\">nums = [1, 2, 3, 4, 5]\n\n# 切片\nnums[1:3]    # [2, 3]\nnums[::-1]   # [5, 4, 3, 2, 1]\n\n# 常用方法\nnums.append(6)           # 尾部追加，O(1)\nnums.extend([7, 8])      # 追加多个\nnums.insert(0, 0)        # 头部插入，O(n) 慎用\nnums.pop()               # 移除尾部，O(1)\nnums.pop(0)              # 移除头部，O(n) 慎用\nnums.remove(3)           # 移除第一个值为 3 的元素\nnums.index(4)            # 找到元素的下标\nnums.sort()              # 原地排序\nsorted(nums)             # 返回新列表\nnums.sort(reverse=True)  # 降序\nnums.sort(key=lambda x: -x)  # 自定义排序\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Ch3 id=\"列表推导式\">列表推导式\u003C\u002Fh3>\n\u003Cpre>\u003Ccode class=\"language-python\"># 基础\nsquares = [x**2 for x in range(10)]\n\n# 带条件\nevens = [x for x in range(20) if x % 2 == 0]\n\n# 双重循环\npairs = [(x, y) for x in [1,2,3] for y in [4,5,6]]\n\n# 对比 Java：\n# List&lt;Integer&gt; squares = IntStream.range(0, 10)\n#     .map(x -&gt; x * x).boxed().collect(Collectors.toList());\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Chr>\n\u003Ch2 id=\"字典\">字典\u003C\u002Fh2>\n\u003Cpre>\u003Ccode class=\"language-python\">d = {&quot;name&quot;: &quot;Alice&quot;, &quot;age&quot;: 25}\n\n# 访问\nd[&quot;name&quot;]           # Alice，不存在时 KeyError\nd.get(&quot;email&quot;)      # None，不存在时返回 None\nd.get(&quot;email&quot;, &quot;&quot;)  # 指定默认值\n\n# 修改\nd[&quot;city&quot;] = &quot;Beijing&quot;\nd.update({&quot;age&quot;: 26, &quot;job&quot;: &quot;dev&quot;})\n\n# 遍历\nfor k, v in d.items():\n    print(f&quot;{k}: {v}&quot;)\n\n# 字典推导式\nsquared = {k: v**2 for k, v in {&quot;a&quot;: 1, &quot;b&quot;: 2}.items()}\n\n# 合并（Python 3.9+）\nmerged = {&quot;a&quot;: 1} | {&quot;b&quot;: 2}   # {'a': 1, 'b': 2}\nd1 = {&quot;a&quot;: 1}\nd1 |= {&quot;b&quot;: 2}                  # 原地合并\n\n# 旧方法（兼容 3.8）\nmerged = {**d1, **d2}\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Chr>\n\u003Ch2 id=\"元组\">元组\u003C\u002Fh2>\n\u003Cpre>\u003Ccode class=\"language-python\">point = (3, 4)\nx, y = point          # 解包\na, *rest = (1, 2, 3, 4)  # a=1, rest=[2, 3, 4]\n\n# 元组可作 dict key（不可变）\ncache = {}\ncache[(0, 0)] = &quot;origin&quot;\n\n# 单元素元组\nsingle = (42,)   # 注意逗号！(42) 只是括号，不是元组\n\n# namedtuple（结构化）\nfrom collections import namedtuple\nPoint = namedtuple(&quot;Point&quot;, [&quot;x&quot;, &quot;y&quot;])\np = Point(3, 4)\nprint(p.x, p.y)  # 3 4\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Chr>\n\u003Ch2 id=\"集合\">集合\u003C\u002Fh2>\n\u003Cpre>\u003Ccode class=\"language-python\">s1 = {1, 2, 3, 4}\ns2 = {3, 4, 5, 6}\n\ns1 &amp; s2    # 交集：{3, 4}\ns1 | s2    # 并集：{1, 2, 3, 4, 5, 6}\ns1 - s2    # 差集：{1, 2}\ns1 ^ s2    # 对称差：{1, 2, 5, 6}\n\n# 去重\nunique = list(set([1, 2, 2, 3, 3, 3]))  # [1, 2, 3]\n\n# 成员检测 O(1)\nprint(3 in s1)   # True\n\n# frozenset（不可变，可作 dict key）\nfs = frozenset([1, 2, 3])\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Chr>\n\u003Ch2 id=\"条件与循环\">条件与循环\u003C\u002Fh2>\n\u003Cpre>\u003Ccode class=\"language-python\"># 三元表达式（类比 Java\u002FJS 的 ? :）\nresult = &quot;yes&quot; if condition else &quot;no&quot;\n\n# for-else（Python 特有！其他语言没有）\nfor item in items:\n    if item == target:\n        break\nelse:\n    # 只有循环正常结束（没有 break）才执行\n    print(&quot;not found&quot;)\n\n# enumerate（带下标的 for）\nfor i, v in enumerate([&quot;a&quot;, &quot;b&quot;, &quot;c&quot;]):\n    print(i, v)  # 0 a \u002F 1 b \u002F 2 c\n\n# zip（同步遍历多个序列）\nfor a, b in zip([1, 2, 3], [&quot;x&quot;, &quot;y&quot;, &quot;z&quot;]):\n    print(a, b)\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Chr>\n\u003Ch2 id=\"函数\">函数\u003C\u002Fh2>\n\u003Cpre>\u003Ccode class=\"language-python\"># 默认参数\ndef connect(host, port=5432, timeout=30):\n    pass\n\n# 关键字参数（顺序无关）\nconnect(host=&quot;localhost&quot;, timeout=10, port=3306)\n\n# *args 和 **kwargs\ndef log(*args, **kwargs):\n    print(args)    # tuple\n    print(kwargs)  # dict\n\nlog(1, 2, 3, level=&quot;info&quot;, tag=&quot;debug&quot;)\n\n# 仅关键字参数（* 之后的参数）\ndef func(a, b, *, key_only):\n    pass\nfunc(1, 2, key_only=3)   # OK\n\n# lambda（适合简单的一次性函数）\nsquare = lambda x: x**2\nnums.sort(key=lambda x: x[1])   # 按第二个元素排序\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Chr>\n\u003Ch2 id=\"解包技巧\">解包技巧\u003C\u002Fh2>\n\u003Cpre>\u003Ccode class=\"language-python\"># 交换变量（Python 独有的优雅）\na, b = b, a\n\n# 扩展解包\nfirst, *middle, last = [1, 2, 3, 4, 5]\n# first=1, middle=[2,3,4], last=5\n\n# _ 作占位符\n_, important, _ = (1, 2, 3)\n\n# 函数参数解包\nargs = (1, 2, 3)\nfunc(*args)          # 等同于 func(1, 2, 3)\n\nkwargs = {&quot;a&quot;: 1, &quot;b&quot;: 2}\nfunc(**kwargs)       # 等同于 func(a=1, b=2)\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Chr>\n\u003Ch2 id=\"with-语句与上下文管理器\">with 语句与上下文管理器\u003C\u002Fh2>\n\u003Cpre>\u003Ccode class=\"language-python\"># 文件操作（自动关闭）\nwith open(&quot;file.txt&quot;, &quot;r&quot;, encoding=&quot;utf-8&quot;) as f:\n    content = f.read()\n# 退出 with 块后文件自动关闭，即使发生异常\n\n# 多个上下文管理器\nwith open(&quot;input.txt&quot;) as fin, open(&quot;output.txt&quot;, &quot;w&quot;) as fout:\n    fout.write(fin.read())\n\n# 自定义上下文管理器\nfrom contextlib import contextmanager\n\n@contextmanager\ndef timer():\n    import time\n    start = time.time()\n    yield\n    print(f&quot;Elapsed: {time.time() - start:.3f}s&quot;)\n\nwith timer():\n    expensive_operation()\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Chr>\n\u003Ch2 id=\"推导式全家桶\">推导式全家桶\u003C\u002Fh2>\n\u003Cpre>\u003Ccode class=\"language-python\">data = range(10)\n\n# list comprehension\nsquares = [x**2 for x in data]\n\n# dict comprehension\nsquare_map = {x: x**2 for x in data}\n\n# set comprehension\nunique_mods = {x % 3 for x in data}\n\n# generator expression（惰性求值，省内存）\ngen = (x**2 for x in data)\ntotal = sum(x**2 for x in data)    # 直接传生成器表达式\n\n# 嵌套推导式\nmatrix = [[1,2,3],[4,5,6],[7,8,9]]\nflat = [x for row in matrix for x in row]\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Chr>\n\u003Ch2 id=\"常用标准库速览\">常用标准库速览\u003C\u002Fh2>\n\u003Cpre>\u003Ccode class=\"language-python\"># pathlib：现代文件路径操作（替代 os.path）\nfrom pathlib import Path\np = Path(&quot;\u002Fhome\u002Fuser\u002Fdocs&quot;)\np \u002F &quot;file.txt&quot;           # 路径拼接\np.exists()               # 是否存在\np.glob(&quot;*.py&quot;)           # 通配符\np.read_text()            # 读取文件\np.write_text(&quot;hello&quot;)    # 写入文件\n\n# json\nimport json\ntext = json.dumps({&quot;key&quot;: &quot;value&quot;}, ensure_ascii=False, indent=2)\ndata = json.loads(text)\n\n# re（正则）\nimport re\nm = re.search(r&quot;\\d+&quot;, &quot;abc123def&quot;)\nm.group()   # 123\nre.findall(r&quot;\\w+&quot;, &quot;hello world&quot;)   # ['hello', 'world']\n\n# datetime\nfrom datetime import datetime, timedelta\nnow = datetime.now()\ntomorrow = now + timedelta(days=1)\nnow.strftime(&quot;%Y-%m-%d %H:%M:%S&quot;)\ndatetime.strptime(&quot;2026-01-01&quot;, &quot;%Y-%m-%d&quot;)\n\n# collections\nfrom collections import Counter, defaultdict, deque\nCounter(&quot;abracadabra&quot;)    # {'a': 5, 'b': 2, ...}\ndd = defaultdict(list)\ndd[&quot;key&quot;].append(1)       # 自动初始化\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Chr>\n\u003Ch2 id=\"快速对比-python-vs-其他语言\">快速对比：Python vs 其他语言\u003C\u002Fh2>\n\u003Ctable>\n\u003Cthead>\n\u003Ctr>\n\u003Cth>特性\u003C\u002Fth>\n\u003Cth>Python\u003C\u002Fth>\n\u003Cth>Java\u002FC++\u003C\u002Fth>\n\u003Cth>JavaScript\u003C\u002Fth>\n\u003C\u002Ftr>\n\u003C\u002Fthead>\n\u003Ctbody>\n\u003Ctr>\n\u003Ctd>变量声明\u003C\u002Ftd>\n\u003Ctd>\u003Ccode>x = 1\u003C\u002Fcode>\u003C\u002Ftd>\n\u003Ctd>\u003Ccode>int x = 1;\u003C\u002Fcode>\u003C\u002Ftd>\n\u003Ctd>\u003Ccode>let x = 1\u003C\u002Fcode>\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n\u003Ctd>字符串插值\u003C\u002Ftd>\n\u003Ctd>\u003Ccode>f&quot;{x}&quot;\u003C\u002Fcode>\u003C\u002Ftd>\n\u003Ctd>\u003Ccode>String.format()\u003C\u002Fcode>\u003C\u002Ftd>\n\u003Ctd>\u003Ccode>`${x}`\u003C\u002Fcode>\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n\u003Ctd>列表\u002F数组\u003C\u002Ftd>\n\u003Ctd>\u003Ccode>list\u003C\u002Fcode>\u003C\u002Ftd>\n\u003Ctd>\u003Ccode>ArrayList\u003C\u002Fcode>\u003C\u002Ftd>\n\u003Ctd>\u003Ccode>Array\u003C\u002Fcode>\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n\u003Ctd>字典\u002FMap\u003C\u002Ftd>\n\u003Ctd>\u003Ccode>dict\u003C\u002Fcode>\u003C\u002Ftd>\n\u003Ctd>\u003Ccode>HashMap\u003C\u002Fcode>\u003C\u002Ftd>\n\u003Ctd>\u003Ccode>Object\u002FMap\u003C\u002Fcode>\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n\u003Ctd>空值\u003C\u002Ftd>\n\u003Ctd>\u003Ccode>None\u003C\u002Fcode>\u003C\u002Ftd>\n\u003Ctd>\u003Ccode>null\u003C\u002Fcode>\u003C\u002Ftd>\n\u003Ctd>\u003Ccode>null\u002Fundefined\u003C\u002Fcode>\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n\u003Ctd>注释\u003C\u002Ftd>\n\u003Ctd>\u003Ccode># ...\u003C\u002Fcode>\u003C\u002Ftd>\n\u003Ctd>\u003Ccode>\u002F\u002F ...\u003C\u002Fcode>\u003C\u002Ftd>\n\u003Ctd>\u003Ccode>\u002F\u002F ...\u003C\u002Fcode>\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003C\u002Ftbody>\n\u003C\u002Ftable>\n\u003Cp>Python 的哲学：\u003Cstrong>显式优于隐式，可读性最重要\u003C\u002Fstrong>（The Zen of Python）。\u003C\u002Fp>\n","2026-05-03",[11,12,13],"python","入门","基础",false,[16,29,40,52,61,68,75,82,89,96,106,115,124,133,141,144,153,162,171,181,188,198,204,211,217,226,233,240,248,258,267,276,286,296,306,314,324,335,345,354,362,368,376,384,392,400,408,415],{"slug":17,"title":18,"description":19,"pub_date":20,"tags":21,"draft":14,"word_count":28},"ide-skills-guide","Agent Skills 完全指南：21 款第三方 Skill 深度评测与使用心得","全面评测 21 款第三方 Agent Skills，涵盖 Vue 生态、前端设计、构建工具、实用工具四大分类。从安装配置到实际使用场景，带你了解每个 Skill 的功能特点、最佳实践与使用心得。","2026-06-15",[22,23,24,25,26,27],"agent","skills","AI","效率工具","前端","Vue",4169,{"slug":30,"title":31,"description":32,"pub_date":33,"tags":34,"draft":14,"word_count":39},"linux-kernel-skeleton-struct-funcptr-container_of","Linux 内核骨架：struct、函数指针与 container_of","读懂 Linux 内核源码的三件套：巨大的 struct 组合代替继承、函数指针表实现虚派发、container_of 宏从嵌入成员找回完整对象。","2026-05-09",[35,36,37,38],"linux","kernel","C","container_of",1369,{"slug":41,"title":42,"description":43,"pub_date":44,"tags":45,"draft":14,"word_count":51},"astro-complete-guide-2025","Astro 5 深度剖析：Islands 架构原理、构建优化与 Cloudflare Workers 边缘部署","从编译器视角解析 Astro 5 的 Islands 架构实现原理，Content Layer API 的 Vite 插件机制，Server Islands 的流式渲染，以及如何在 Cloudflare Workers + D1 边缘环境下榨干性能。","2026-05-08",[46,47,48,49,50],"astro","frontend","cloudflare","performance","architecture",3663,{"slug":53,"title":54,"description":55,"pub_date":9,"tags":56,"draft":14,"word_count":60},"llm-prompt-engineering","Prompt Engineering 实战：让 LLM 真正听话的技巧","System prompt 怎么写、Few-shot 怎么设计、Chain-of-Thought 原理，以及常见失败模式和调试方法。",[57,58,59],"ai","llm","工程实践",1723,{"slug":62,"title":63,"description":64,"pub_date":9,"tags":65,"draft":14,"word_count":67},"rag-system-design","RAG 系统设计：从 naive 到 production-ready","Retrieval-Augmented Generation 不只是「向量数据库 + LLM」，分块策略、召回质量、重排序、缓存才是工程核心。",[57,66,58,59],"rag",1613,{"slug":69,"title":70,"description":71,"pub_date":9,"tags":72,"draft":14,"word_count":74},"git-advanced-workflow","Git 进阶工作流：rebase、cherry-pick、bisect 的正确使用","merge 会了，但 rebase 总搞错？bisect 找 bug 提交？interactive rebase 整理历史？这篇一次说清楚。",[73,59],"git",1396,{"slug":76,"title":77,"description":78,"pub_date":9,"tags":79,"draft":14,"word_count":81},"docker-practical-guide","Docker 实战：从会用到用好","会 docker run 不够，Dockerfile 最佳实践、多阶段构建、Compose 编排、镜像瘦身才是日常真正需要的。",[80,35,59],"docker",1268,{"slug":83,"title":84,"description":85,"pub_date":9,"tags":86,"draft":14,"word_count":88},"anthropics-skills-guide","anthropics\u002Fskills：Anthropic 官方 Agent Skills 仓库解析","Anthropic 官方开源的 Agent Skills 标准仓库，127k stars，解析 SKILL.md 规范、17 个示例 skill 的设计模式，以及如何在 Claude Code \u002F Claude.ai \u002F API 中使用",[57,87,22,23],"Claude",2090,{"slug":90,"title":91,"description":92,"pub_date":9,"tags":93,"draft":14,"word_count":95},"karpathy-claude-code-guidelines","Karpathy 的 LLM 编码批评与 CLAUDE.md 最佳实践","基于 Andrej Karpathy 对 LLM 编程助手的观察，forrestchang 提炼出一个 CLAUDE.md 文件，4 条原则解决 AI 编码的典型失控问题：乱猜假设、过度设计、乱改代码、目标不清",[57,87,94,59],"Claude Code",2699,{"slug":97,"title":98,"description":99,"pub_date":9,"tags":100,"draft":14,"word_count":105},"typescript-advanced-patterns","TypeScript 高级模式：让类型系统为你工作","基础 TS 会了但类型总是 any？条件类型、映射类型、模板字面量类型、infer 关键字才是 TS 的真正威力。",[101,102,103,104],"typescript","类型系统","前端工程","高级模式",1419,{"slug":107,"title":108,"description":109,"pub_date":9,"tags":110,"draft":14,"word_count":114},"linux-performance-tuning","Linux 性能调优实战：从 top 到 perf 的完整工具链","遇到性能问题不知道从哪下手？这篇建立系统化的排查思路，从 CPU\u002F内存\u002FIO\u002F网络逐层分析。",[35,111,112,113],"性能","运维","系统编程",1524,{"slug":116,"title":117,"description":118,"pub_date":9,"tags":119,"draft":14,"word_count":123},"python-functional-programming","Python 函数式编程：map\u002Ffilter\u002Freduce 之外","Python 不是纯函数式语言，但 functools、itertools、偏函数、闭包这些工具用好了能让代码简洁一个量级。",[11,120,121,122],"函数式","闭包","装饰器",1867,{"slug":125,"title":126,"description":127,"pub_date":9,"tags":128,"draft":14,"word_count":132},"python-oop-guide","Python 面向对象：__init__ 之外你需要知道的","Python OOP 不只是 class + __init__，魔术方法、描述符、元类才是真正的武器。",[11,129,130,131],"OOP","面向对象","魔术方法",1792,{"slug":134,"title":135,"description":136,"pub_date":9,"tags":137,"draft":14,"word_count":140},"python-data-structures","Python 内置数据结构深度解析","list、dict、set、tuple 不只是数据容器，搞懂它们的底层实现和时间复杂度，才能写出高性能 Python。",[11,138,111,139],"数据结构","算法",1517,{"slug":4,"title":5,"description":6,"pub_date":9,"tags":142,"draft":14,"word_count":143},[11,12,13],1607,{"slug":145,"title":146,"description":147,"pub_date":9,"tags":148,"draft":14,"word_count":152},"python-dataclass-pydantic","Python dataclass vs Pydantic：数据类选型指南","dataclass 是标准库的轻量选择，Pydantic v2 是带验证的重武器，什么时候用哪个，这篇说清楚。",[11,149,150,151],"dataclass","pydantic","数据验证",1323,{"slug":154,"title":155,"description":156,"pub_date":9,"tags":157,"draft":14,"word_count":161},"python-asyncio-practical","Python asyncio 实战：从回调地狱到协程优雅","asyncio 是 Python 异步编程的核心，搞懂 event loop、Task、gather 这些概念才能写出真正高效的异步代码。",[11,158,159,160],"asyncio","并发","网络编程",1258,{"slug":163,"title":164,"description":165,"pub_date":9,"tags":166,"draft":14,"word_count":170},"python-type-hints-guide","Python 类型注解完全指南：从入门到实践","Python 3.5+ 引入类型注解，配合 mypy\u002Fpyright 让 Python 也能享受静态类型检查的好处。",[11,167,168,169],"typescript-style","type-hints","工具链",1102,{"slug":172,"title":173,"description":174,"pub_date":175,"tags":176,"draft":14,"word_count":180},"pwa-install-update-button","PWA 踩坑：为什么安装按钮从来不出现","从 beforeinstallprompt 到 Service Worker waiting，把 PWA 的安装与更新提示真正做对","2026-05-02",[177,178,179],"pwa","javascript","web",1683,{"slug":182,"title":183,"description":184,"pub_date":185,"tags":186,"draft":14,"word_count":187},"openclaw-vs-hermes-agent","OpenClaw vs Hermes Agent：两个本地优先 Agent 的设计差异","OpenClaw（Novita AI）和 Hermes Agent（Nous Research）都是本地运行的个人 AI Agent，但在记忆系统、技能学习、运行环境和模型生态上走了不同的路。深入对比两种架构的核心差异。","2026-05-01",[57,22,58],1679,{"slug":189,"title":190,"description":191,"pub_date":185,"tags":192,"draft":14,"word_count":197},"cpp-random-design-patterns","C++ 设计模式实战：RAII、观察者、工厂","用现代 C++（C++17\u002F20）实现三种高频设计模式：RAII 资源管理、观察者模式事件系统、工厂模式插件架构。每种模式给出问题场景、实现代码和真实工程案例。",[193,194,195,196],"cpp","设计模式","c++17","工程",2613,{"slug":199,"title":200,"description":201,"pub_date":185,"tags":202,"draft":14,"word_count":203},"data-structures-fundamentals","数据结构基础：从数组到红黑树","系统梳理常用数据结构的核心原理、时间复杂度和适用场景。数组、链表、栈、队列、哈希表、二叉树、堆、图，每种结构附实现要点和 C++ 代码片段。",[138,139,193,13],3004,{"slug":205,"title":206,"description":207,"pub_date":208,"tags":209,"draft":14,"word_count":210},"ai-agent-what-is","什么是 AI Agent？从 LLM 到自主执行","LLM 本身是无状态问答机，Agent 是什么让它’动’起来的？本文深入解析 Agent 的四个核心能力、ReAct 框架、工具调用原理，以及主流框架横向对比。","2026-04-30",[57,22,58],2116,{"slug":212,"title":213,"description":214,"pub_date":208,"tags":215,"draft":14,"word_count":216},"ai-agent-memory","AI Agent 的记忆系统：从上下文窗口到长期记忆","深入拆解 AI Agent 的四种记忆类型、上下文窗口压缩策略、RAG 向量检索原理，以及三种典型失败模式和工程选型建议。",[57,22,66],2052,{"slug":218,"title":219,"description":220,"pub_date":208,"tags":221,"draft":14,"word_count":225},"network-proxy-vpn-guide","代理与翻墙技术原理：从 HTTP 代理到现代协议","深入解析代理与 VPN 的本质区别，梳理从 SOCKS5 到 Shadowsocks、V2Ray\u002FXray、Hysteria2 的协议演进，以及机场订阅的技术本质。",[222,223,224],"网络","代理","协议",2148,{"slug":227,"title":228,"description":229,"pub_date":208,"tags":230,"draft":14,"word_count":143},"algorithm-binary-search","二分查找：永远写不对？记住这个模板","彻底搞清楚二分查找的边界问题：闭区间和左闭右开两套模板、三道经典 LeetCode 题目完整 C++ 实现，以及二分答案的进阶思路。",[139,231,232,193],"二分查找","leetcode",{"slug":234,"title":235,"description":236,"pub_date":208,"tags":237,"draft":14,"word_count":239},"algorithm-sliding-window","滑动窗口算法：从暴力到 O(n) 的思维跃迁","系统讲解滑动窗口算法的核心模板、适用题型，配合三道经典 LeetCode 题目的完整 C++ 实现，彻底理解双指针收缩思路。",[139,238,232,193],"滑动窗口",1943,{"slug":241,"title":242,"description":243,"pub_date":208,"tags":244,"draft":14,"word_count":247},"network-clash-config","Clash \u002F Mihomo 配置详解：规则、策略组与分流","深入解析 Clash\u002FMihomo 的核心配置结构，包括代理节点、策略组类型、规则优先级、DNS fake-ip 模式，以及一份实用的完整配置模板。",[222,245,223,246],"clash","配置",1292,{"slug":249,"title":250,"description":251,"pub_date":252,"tags":253,"draft":14,"word_count":257},"hid-hotplug","HID 设备热插拔检测：从 udev 到 node-hid","在 Linux 上用 node-hid + usb 库实现可靠的 USB HID 设备热插拔检测，踩坑记录","2026-04-28",[193,254,35,255,256],"hid","nodejs","electron",2039,{"slug":259,"title":260,"description":261,"pub_date":262,"tags":263,"draft":14,"word_count":266},"electron-ipc-types","Electron IPC 类型安全：从 any 到完全类型化","用 TypeScript 泛型封装 Electron IPC，彻底消灭 any，preload 契约集中管理","2026-04-25",[256,101,264,265],"ipc","vue",1446,{"slug":268,"title":269,"description":270,"pub_date":271,"tags":272,"draft":14,"word_count":275},"element-plus-popover-hide","手动关闭多个 el-popover（不用 v-model:visible）","通过 ref + Reflect.get 调用 hide() 方法手动关闭 Element Plus Popover，解释 Vue3 Proxy 导致无法直接调用实例方法的原因。","2024-10-25",[265,273,274],"element-plus","vue3",1321,{"slug":277,"title":278,"description":279,"pub_date":280,"tags":281,"draft":14,"word_count":285},"vite-vue3-ts-elementplus-pinia","用 Vite+（vp）从零搭建 Vue3 + TypeScript + Element Plus + Pinia + Vue Router","使用 Vite+ 统一工具链（vp）一条命令搭建 Vue3 全家桶，涵盖按需导入、Pinia store、路由配置，以及常见坑的解决方案。","2024-08-27",[265,282,101,273,283,284],"vite","pinia","vite-plus",1960,{"slug":287,"title":288,"description":289,"pub_date":290,"tags":291,"draft":14,"word_count":295},"cef-lnk2038-iterator-debug-level","CEF LNK2038：解决 _ITERATOR_DEBUG_LEVEL 不匹配错误","分析 CEF（Chromium Embedded Framework）集成时出现的 LNK2038 _ITERATOR_DEBUG_LEVEL 链接错误，从根本原因到解决方案的完整指南。","2024-05-07",[193,292,293,294],"CEF","Visual Studio","链接错误",1509,{"slug":297,"title":298,"description":299,"pub_date":300,"tags":301,"draft":14,"word_count":305},"npm-electron-install-fix","彻底解决 npm 安装 Electron 失败的问题","分析 npm install electron 失败的根本原因（下载二进制超时\u002F被墙），通过国内镜像（npmmirror）彻底解决，并介绍多种备选方案和常见错误排查。","2024-03-01",[256,302,303,304],"npm","前端工具链","国内镜像",1494,{"slug":307,"title":308,"description":309,"pub_date":310,"tags":311,"draft":14,"word_count":313},"git-out-of-memory","解决 git 报错：Fatal: Out of memory, malloc failed","分析 git 大仓库操作时出现 Out of memory malloc failed 的根本原因，通过调整 pack.windowMemory、http.postBuffer 和 git repack 彻底解决。","2024-01-31",[73,35,312],"工具",2244,{"slug":315,"title":316,"description":317,"pub_date":318,"tags":319,"draft":14,"word_count":323},"vmware-tools-install","在 VMware 虚拟机中安装 open-vm-tools 完整指南","详解 VMware Tools 的作用、open-vm-tools 与官方 VMware Tools 的区别，以及在 Ubuntu 虚拟机中安装并生效的完整步骤和常见问题排查。","2023-11-21",[320,35,321,322],"VMware","Ubuntu","虚拟机",2523,{"slug":325,"title":326,"description":327,"pub_date":328,"tags":329,"draft":14,"word_count":334},"load-balancing-algorithms","负载均衡算法完全指南：从轮询到一致性哈希","系统梳理静态与动态负载均衡算法，涵盖轮询、随机、权重、IP Hash、一致性 Hash、最少连接、最快响应等，并对比 Nginx、Dubbo、Spring Cloud LoadBalancer 的实现差异。","2023-11-15",[330,331,332,333],"分布式","负载均衡","Nginx","微服务",1764,{"slug":336,"title":337,"description":338,"pub_date":339,"tags":340,"draft":14,"word_count":344},"win-cw2a-ca2w","ATL 字符串转换：CW2A 与 CA2W 完全指南","详解 ATL 宏 CW2A\u002FCA2W 在 Unicode 与 ANSI 之间的字符串转换用法、头文件依赖、USES_CONVERSION 宏的作用与常见陷阱。","2023-06-09",[193,341,342,343],"windows","ATL","字符串",1665,{"slug":346,"title":347,"description":348,"pub_date":339,"tags":349,"draft":14,"word_count":353},"csharp-sendmessage-cpp","C# 通过 SendMessage 向 C++ 窗口发送消息与字符串","使用 P\u002FInvoke 调用 user32.dll 的 SendMessage，从 C# 发送自定义 WM_USER 消息及字符串指针给 C++ 原生窗口，并在 C++ 侧正确接收和转换。",[350,193,341,351,352],"C#","互操作","PInvoke",1554,{"slug":355,"title":356,"description":357,"pub_date":358,"tags":359,"draft":14,"word_count":361},"win-postmessage-vector","Windows PostMessage 跨线程传递 std::vector 指针","通过 PostMessage 在 Windows 消息队列中传递 std::vector 指针，使用 reinterpret_cast 将指针装入 LPARAM，并在接收方正确释放内存。","2023-05-26",[193,341,360],"WinAPI",1823,{"slug":363,"title":364,"description":365,"pub_date":358,"tags":366,"draft":14,"word_count":367},"exe-dll-single-package","将 EXE 和 DLL 打包成单一可执行文件","介绍两种将 exe 和依赖 dll 打包成单文件的方案：Enigma Virtual Box 和 WinRAR 自解压，适合发布 Windows 桌面程序时简化分发流程。",[341,193,312],1619,{"slug":369,"title":370,"description":371,"pub_date":358,"tags":372,"draft":14,"word_count":375},"cpp-random-mt19937","C++ 现代随机数生成：用 mt19937 彻底告别 rand()","深入讲解为什么 rand() 不够用，以及如何用 C++11 的 \u003Crandom> 库正确生成高质量随机数，涵盖 mt19937、各种分布和线程安全。",[193,373,374],"c++11","random",1549,{"slug":377,"title":378,"description":379,"pub_date":380,"tags":381,"draft":14,"word_count":383},"win-startup-registry","C++ 实现程序开机自启动：注册表方式详解","通过操作 Windows 注册表 Run 键实现程序开机自启动，包括 HKCU 与 HKLM 区别、完整封装代码、工作目录问题和 UAC 权限处理。","2022-12-26",[341,193,382],"registry",1201,{"slug":385,"title":386,"description":387,"pub_date":388,"tags":389,"draft":14,"word_count":391},"mfc-cstring-wparam","MFC 中 CString 与 WPARAM 之间的转换","详解 MFC 消息传递中 CString 无法直接强转为 WPARAM 的原因，以及两种正确的转换方案，并介绍结构体指针传递的正确姿势。","2022-11-25",[390,193,341],"mfc",1546,{"slug":393,"title":394,"description":395,"pub_date":396,"tags":397,"draft":14,"word_count":399},"duilib-static-build","正确编译 Duilib 静态库：避免 ATL 依赖和链接错误","详解如何用 DuiLib_Static.vcxproj 编译 Duilib 静态库，解决 VARIANT 未定义、Unicode 配置不匹配和 ATL 依赖等常见问题。","2022-08-24",[193,398,341,390],"duilib",2639,{"slug":401,"title":402,"description":403,"pub_date":404,"tags":405,"draft":14,"word_count":407},"mfc-dpi-adaptive","MFC 界面自适应不同分辨率","MFC 对话框程序实现控件和字体随分辨率自动缩放的完整方案，附 DPI Awareness 配置说明","2022-08-17",[390,193,341,406],"dpi",1414,{"slug":409,"title":410,"description":411,"pub_date":412,"tags":413,"draft":14,"word_count":414},"mfc-drag-window","MFC 无标题栏窗口客户区拖动：三种方法对比","MFC 对话框去掉标题栏后如何实现拖动移动窗口，三种方案完整实现与适用场景分析","2022-08-16",[390,193,341],1633,{"slug":416,"title":417,"description":418,"pub_date":419,"tags":420,"draft":14,"word_count":422},"algorithm-number-complement","整数的补数：位运算掩码解法","LeetCode 476 题，用掩码 XOR 实现整数补数，附 C++\u002FPython\u002FJava 三种实现及补数与补码的区别","2021-03-08",[139,421,232],"位运算",1374,[]]