{"id":12,"date":"2026-06-12T18:14:52","date_gmt":"2026-06-12T10:14:52","guid":{"rendered":"https:\/\/www.52runoob.com\/?p=12"},"modified":"2026-06-12T18:14:53","modified_gmt":"2026-06-12T10:14:53","slug":"%f0%9f%90%8d-python-3-%e7%bb%88%e6%9e%81%e6%b7%b1%e5%ba%a6%e6%8c%87%e5%8d%97%ef%bc%9a%e4%bb%8e%e5%ba%95%e5%b1%82%e5%8e%9f%e7%90%86%e5%88%b0%e6%9e%b6%e6%9e%84%e7%ba%a7%e6%8e%8c%e6%8f%a1","status":"publish","type":"post","link":"https:\/\/www.52runoob.com\/index.php\/2026\/06\/12\/%f0%9f%90%8d-python-3-%e7%bb%88%e6%9e%81%e6%b7%b1%e5%ba%a6%e6%8c%87%e5%8d%97%ef%bc%9a%e4%bb%8e%e5%ba%95%e5%b1%82%e5%8e%9f%e7%90%86%e5%88%b0%e6%9e%b6%e6%9e%84%e7%ba%a7%e6%8e%8c%e6%8f%a1\/","title":{"rendered":"\ud83d\udc0d Python 3 \u7ec8\u6781\u6df1\u5ea6\u6307\u5357\uff1a\u4ece\u5e95\u5c42\u539f\u7406\u5230\u67b6\u6784\u7ea7\u638c\u63e1"},"content":{"rendered":"\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u76ee\u5f55 (\u7ad9\u5185\u5bfc\u822a)<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"#\u7b2c\u4e00\u90e8\u5206python-\u54f2\u5b66\u5386\u53f2\u4e0e\u73b0\u4ee3\u751f\u6001\">\u7b2c\u4e00\u90e8\u5206\uff1aPython \u54f2\u5b66\u3001\u5386\u53f2\u4e0e\u73b0\u4ee3\u751f\u6001<\/a><\/li>\n\n\n\n<li><a href=\"#\u7b2c\u4e8c\u90e8\u5206\u73b0\u4ee3-python-\u5de5\u7a0b\u5316\u4e0e\u73af\u5883\u7ba1\u7406\">\u7b2c\u4e8c\u90e8\u5206\uff1a\u73b0\u4ee3 Python \u5de5\u7a0b\u5316\u4e0e\u73af\u5883\u7ba1\u7406<\/a><\/li>\n\n\n\n<li><a href=\"#\u7b2c\u4e09\u90e8\u5206\u6838\u5fc3\u8bed\u6cd5\u4e0e\u6570\u636e\u6a21\u578b\u5e95\u5c42\u5256\u6790\">\u7b2c\u4e09\u90e8\u5206\uff1a\u6838\u5fc3\u8bed\u6cd5\u4e0e\u6570\u636e\u6a21\u578b\u5e95\u5c42\u5256\u6790<\/a><\/li>\n\n\n\n<li><a href=\"#\u7b2c\u56db\u90e8\u5206\u51fd\u6570\u5f0f\u7f16\u7a0b\u4e0e\u9ad8\u7ea7\u7279\u6027\">\u7b2c\u56db\u90e8\u5206\uff1a\u51fd\u6570\u5f0f\u7f16\u7a0b\u4e0e\u9ad8\u7ea7\u7279\u6027<\/a><\/li>\n\n\n\n<li><a href=\"#\u7b2c\u4e94\u90e8\u5206\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b-oop-\u4e0e\u5143\u7f16\u7a0b\">\u7b2c\u4e94\u90e8\u5206\uff1a\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b (OOP) \u4e0e\u5143\u7f16\u7a0b<\/a><\/li>\n\n\n\n<li><a href=\"#\u7b2c\u516d\u90e8\u5206\u5e76\u53d1\u7f16\u7a0b\u4e0e\u5f02\u6b65-io-asyncio\">\u7b2c\u516d\u90e8\u5206\uff1a\u5e76\u53d1\u7f16\u7a0b\u4e0e\u5f02\u6b65 I\/O (Asyncio)<\/a><\/li>\n\n\n\n<li><a href=\"#\u7b2c\u4e03\u90e8\u5206\u5f02\u5e38\u5904\u7406\u8c03\u8bd5\u4e0e\u6d4b\u8bd5\u9a71\u52a8\u5f00\u53d1-tdd\">\u7b2c\u4e03\u90e8\u5206\uff1a\u5f02\u5e38\u5904\u7406\u3001\u8c03\u8bd5\u4e0e\u6d4b\u8bd5\u9a71\u52a8\u5f00\u53d1 (TDD)<\/a><\/li>\n\n\n\n<li><a href=\"#\u7b2c\u516b\u90e8\u5206\u6027\u80fd\u4f18\u5316\u7c7b\u578b\u63d0\u793a\u4e0e\u4ee3\u7801\u89c4\u8303\">\u7b2c\u516b\u90e8\u5206\uff1a\u6027\u80fd\u4f18\u5316\u3001\u7c7b\u578b\u63d0\u793a\u4e0e\u4ee3\u7801\u89c4\u8303<\/a><\/li>\n\n\n\n<li><a href=\"#\u9644\u5f55\u94fe\u63a5\u4e0e\u8d44\u6e90\u6c47\u603b\">\u9644\u5f55\uff1a\u94fe\u63a5\u4e0e\u8d44\u6e90\u6c47\u603b<\/a><\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u7b2c\u4e00\u90e8\u5206\uff1aPython \u54f2\u5b66\u3001\u5386\u53f2\u4e0e\u73b0\u4ee3\u751f\u6001<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1.1 Python \u4e4b\u7985 (The Zen of Python)<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Python \u7684\u8bbe\u8ba1\u54f2\u5b66\u6df1\u6df1\u690d\u6839\u4e8e\u5176\u8bed\u6cd5\u548c\u6807\u51c6\u5e93\u4e2d\u3002\u901a\u8fc7\u5728\u89e3\u91ca\u5668\u4e2d\u8fd0\u884c <code>import this<\/code>\uff0c\u6211\u4eec\u53ef\u4ee5\u7aa5\u89c1\u5176\u6838\u5fc3\u601d\u60f3\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<ul class=\"wp-block-list\">\n<li>Beautiful is better than ugly. (\u4f18\u7f8e\u80dc\u4e8e\u4e11\u964b)<\/li>\n\n\n\n<li>Explicit is better than implicit. (\u660e\u4e86\u80dc\u4e8e\u6666\u6da9)<\/li>\n\n\n\n<li>Simple is better than complex. (\u7b80\u5355\u80dc\u4e8e\u590d\u6742)<\/li>\n\n\n\n<li>Complex is better than complicated. (\u590d\u6742\u80dc\u4e8e\u51cc\u4e71)<\/li>\n\n\n\n<li>Readability counts. (\u53ef\u8bfb\u6027\u81f3\u5173\u91cd\u8981)<\/li>\n<\/ul>\n<\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\">1.2 Python 2 \u5230 Python 3 \u7684\u6f14\u8fdb\u4e0e\u73b0\u72b6<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Python 3 \u4e8e 2008 \u5e74\u53d1\u5e03\uff0c\u65e8\u5728\u4fee\u590d Python 2 \u4e2d\u7684\u6839\u672c\u6027\u8bbe\u8ba1\u7f3a\u9677\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Unicode \u9ed8\u8ba4\u5316<\/strong>\uff1aPython 3 \u4e2d <code>str<\/code> \u9ed8\u8ba4\u4e3a Unicode\uff0c<code>bytes<\/code> \u7528\u4e8e\u8868\u793a\u5b57\u8282\u5e8f\u5217\uff0c\u5f7b\u5e95\u89e3\u51b3\u4e86\u591a\u8bed\u8a00\u7f16\u7801\u75db\u70b9\u3002<\/li>\n\n\n\n<li><strong>\u6253\u5370\u51fd\u6570\u5316<\/strong>\uff1a<code>print<\/code> \u4ece\u8bed\u53e5\u53d8\u4e3a\u51fd\u6570 <code>print()<\/code>\uff0c\u63d0\u9ad8\u4e86\u8bed\u6cd5\u7684\u4e00\u81f4\u6027\u3002<\/li>\n\n\n\n<li><strong>\u6574\u6570\u7edf\u4e00<\/strong>\uff1a\u79fb\u9664\u4e86 <code>int<\/code> \u548c <code>long<\/code> \u7684\u533a\u522b\uff0c\u6240\u6709\u6574\u6570\u5747\u4e3a\u4efb\u610f\u7cbe\u5ea6\u3002<\/li>\n\n\n\n<li><strong>\u73b0\u72b6 (\u622a\u81f3 2026 \u5e74)<\/strong>\uff1aPython 2 \u5df2\u4e8e 2020 \u5e74\u6b63\u5f0f\u9000\u5f79\u3002\u5f53\u524d\u4e3b\u6d41\u7248\u672c\u4e3a Python 3.11 &#8211; 3.13\uff0c\u8fd9\u4e9b\u7248\u672c\u5f15\u5165\u4e86\u663e\u8457\u7684\u6027\u80fd\u63d0\u5347\uff08\u5982 Python 3.11 \u7684 &#8220;Faster CPython&#8221; \u9879\u76ee\uff0c\u901f\u5ea6\u63d0\u5347 10-60%\uff09\u4ee5\u53ca\u66f4\u53cb\u597d\u7684\u9519\u8bef\u8ffd\u8e2a\uff08Enhanced Error Messages\uff09\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">1.3 \u5168\u5c40\u89e3\u91ca\u5668\u9501 (GIL) \u7684\u6df1\u5ea6\u89e3\u6790<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">GIL (Global Interpreter Lock) \u662f CPython \u89e3\u91ca\u5668\u4e2d\u7684\u4e00\u4e2a\u4e92\u65a5\u9501\uff0c\u5b83\u786e\u4fdd\u540c\u4e00\u65f6\u523b\u53ea\u6709\u4e00\u4e2a\u7ebf\u7a0b\u6267\u884c Python \u5b57\u8282\u7801\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u4e3a\u4ec0\u4e48\u5b58\u5728 GIL\uff1f<\/strong> \u4e3b\u8981\u662f\u4e3a\u4e86\u7b80\u5316 CPython \u7684\u5185\u5b58\u7ba1\u7406\uff08\u7279\u522b\u662f\u5f15\u7528\u8ba1\u6570\u673a\u5236\uff09\uff0c\u907f\u514d\u591a\u7ebf\u7a0b\u73af\u5883\u4e0b\u7684\u7ade\u6001\u6761\u4ef6\u3002<\/li>\n\n\n\n<li><strong>GIL \u7684\u5f71\u54cd<\/strong>\uff1a\u5bf9\u4e8e <strong>CPU \u5bc6\u96c6\u578b<\/strong> \u4efb\u52a1\uff0c\u591a\u7ebf\u7a0b\u65e0\u6cd5\u5229\u7528\u591a\u6838 CPU\uff0c\u751a\u81f3\u53ef\u80fd\u56e0\u4e3a\u7ebf\u7a0b\u5207\u6362\u5f00\u9500\u5bfc\u81f4\u6027\u80fd\u4e0b\u964d\u3002\u5bf9\u4e8e <strong>I\/O \u5bc6\u96c6\u578b<\/strong> \u4efb\u52a1\uff08\u5982\u7f51\u7edc\u8bf7\u6c42\u3001\u6587\u4ef6\u8bfb\u5199\uff09\uff0cGIL \u4f1a\u5728 I\/O \u963b\u585e\u65f6\u88ab\u91ca\u653e\uff0c\u56e0\u6b64\u591a\u7ebf\u7a0b\u4f9d\u7136\u6709\u6548\u3002<\/li>\n\n\n\n<li><strong>\u89e3\u51b3\u65b9\u6848<\/strong>\uff1a<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u4f7f\u7528 <code>multiprocessing<\/code> \u6a21\u5757\u7ed5\u8fc7 GIL\uff0c\u5229\u7528\u591a\u6838\u3002<\/li>\n\n\n\n<li>\u4f7f\u7528 C \u6269\u5c55\uff08\u5982 NumPy\uff09\uff0c\u5728 C \u4ee3\u7801\u6267\u884c\u671f\u95f4\u91ca\u653e GIL\u3002<\/li>\n\n\n\n<li>\u91c7\u7528\u5f02\u6b65 I\/O (<code>asyncio<\/code>) \u5904\u7406\u9ad8\u5e76\u53d1\u7f51\u7edc\u8bf7\u6c42\u3002<\/li>\n\n\n\n<li>\u5173\u6ce8 Python 3.13+ \u7684\u5b9e\u9a8c\u6027 <strong>Free-threaded Python (PEP 703)<\/strong>\uff0c\u65e8\u5728\u6700\u7ec8\u79fb\u9664 GIL\u3002<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u7b2c\u4e8c\u90e8\u5206\uff1a\u73b0\u4ee3 Python \u5de5\u7a0b\u5316\u4e0e\u73af\u5883\u7ba1\u7406<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u73b0\u4ee3\u8f6f\u4ef6\u5f00\u53d1\u4e2d\uff0c\u4f9d\u8d56\u9694\u79bb\u548c\u53ef\u91cd\u590d\u6784\u5efa\u662f\u81f3\u5173\u91cd\u8981\u7684\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2.1 \u865a\u62df\u73af\u5883 (Virtual Environments)<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u865a\u62df\u73af\u5883\u4e3a\u6bcf\u4e2a\u9879\u76ee\u521b\u5efa\u4e86\u72ec\u7acb\u7684 Python \u8fd0\u884c\u65f6\u548c\u5305\u5b89\u88c5\u76ee\u5f55\uff0c\u907f\u514d\u5168\u5c40\u6c61\u67d3\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># 1. \u4f7f\u7528\u5185\u7f6e venv \u521b\u5efa\u865a\u62df\u73af\u5883 (\u63a8\u8350)\npython3 -m venv myenv\n\n# 2. \u6fc0\u6d3b\u865a\u62df\u73af\u5883\n# macOS \/ Linux:\nsource myenv\/bin\/activate\n# Windows:\nmyenv\\Scripts\\activate\n\n# 3. \u9a8c\u8bc1\u73af\u5883\u9694\u79bb\nwhich python  # \u5e94\u6307\u5411 myenv \u76ee\u5f55\u4e0b\u7684 python<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2.2 \u73b0\u4ee3\u4f9d\u8d56\u7ba1\u7406\u5de5\u5177\u5bf9\u6bd4<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th class=\"has-text-align-left\" data-align=\"left\">\u5de5\u5177<\/th><th class=\"has-text-align-left\" data-align=\"left\">\u7279\u70b9<\/th><th class=\"has-text-align-left\" data-align=\"left\">\u9002\u7528\u573a\u666f<\/th><\/tr><\/thead><tbody><tr><td class=\"has-text-align-left\" data-align=\"left\"><code>pip<\/code> + <code>requirements.txt<\/code><\/td><td class=\"has-text-align-left\" data-align=\"left\">\u5b98\u65b9\u57fa\u7840\u5de5\u5177\uff0c\u7b80\u5355\u76f4\u63a5\u3002<\/td><td class=\"has-text-align-left\" data-align=\"left\">\u5c0f\u578b\u811a\u672c\u3001Docker \u955c\u50cf\u6784\u5efa\u3002<\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\"><code>Poetry<\/code><\/td><td class=\"has-text-align-left\" data-align=\"left\">\u73b0\u4ee3\u4f9d\u8d56\u7ba1\u7406\uff0c\u652f\u6301 <code>pyproject.toml<\/code>\uff0c\u81ea\u52a8\u89e3\u51b3\u4f9d\u8d56\u51b2\u7a81\uff0c\u5185\u7f6e\u53d1\u5e03\u529f\u80fd\u3002<\/td><td class=\"has-text-align-left\" data-align=\"left\">\u4e2d\u5927\u578b\u9879\u76ee\u3001\u5f00\u6e90\u5e93\u5f00\u53d1\u3002<\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\"><code>Pipenv<\/code><\/td><td class=\"has-text-align-left\" data-align=\"left\">\u7ed3\u5408\u4e86 <code>pip<\/code> \u548c <code>virtualenv<\/code>\uff0c\u4f7f\u7528 <code>Pipfile<\/code> \u548c <code>Pipfile.lock<\/code>\u3002<\/td><td class=\"has-text-align-left\" data-align=\"left\">\u9700\u8981\u7b80\u5355\u4f9d\u8d56\u9501\u5b9a\u7684 Web \u5e94\u7528\u3002<\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\"><code>uv<\/code> (\u65b0\u5174)<\/td><td class=\"has-text-align-left\" data-align=\"left\">\u7531 Rust \u7f16\u5199\u7684\u8d85\u9ad8\u901f Python \u5305\u5b89\u88c5\u5668\u548c\u89e3\u6790\u5668\uff0c\u517c\u5bb9 pip \u63a5\u53e3\u3002<\/td><td class=\"has-text-align-left\" data-align=\"left\">\u8ffd\u6c42\u6781\u81f4\u5b89\u88c5\u901f\u5ea6\u7684\u73b0\u4ee3\u9879\u76ee (2024+ \u8d8b\u52bf)\u3002<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">2.3 <code>pyproject.toml<\/code> \u6807\u51c6<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">PEP 518 \u548c PEP 621 \u786e\u7acb\u4e86 <code>pyproject.toml<\/code> \u4f5c\u4e3a Python \u9879\u76ee\u914d\u7f6e\u7684\u5355\u4e00\u4e8b\u5b9e\u6765\u6e90\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># pyproject.toml \u793a\u4f8b<\/code><\/pre>\n\n\n<p>[project]<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">name = &#8220;my_awesome_project&#8221; version = &#8220;0.1.0&#8221; description = &#8220;A demonstration of modern Python packaging&#8221; requires-python = &#8220;&gt;=3.10&#8221; dependencies = [ &#8220;requests&gt;=2.28.0&#8221;, &#8220;pydantic&gt;=2.0.0&#8221;, ]<\/p>\n\n\n<p>[project.optional-dependencies]<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">dev = [ &#8220;pytest&gt;=7.0.0&#8221;, &#8220;black&gt;=23.0.0&#8221;, ]<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u7b2c\u4e09\u90e8\u5206\uff1a\u6838\u5fc3\u8bed\u6cd5\u4e0e\u6570\u636e\u6a21\u578b\u5e95\u5c42\u5256\u6790<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">3.1 \u53d8\u91cf\u4e0e\u5185\u5b58\u7ba1\u7406\uff1a\u5f15\u7528\u8ba1\u6570\u4e0e\u5783\u573e\u56de\u6536<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728 Python \u4e2d\uff0c<strong>\u53d8\u91cf\u53ea\u662f\u5bf9\u8c61\u7684\u5f15\u7528\uff08\u6807\u7b7e\uff09<\/strong>\uff0c\u5bf9\u8c61\u672c\u8eab\u5b58\u50a8\u5728\u5806\u5185\u5b58\u4e2d\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u5f15\u7528\u8ba1\u6570 (Reference Counting)<\/strong>\uff1a\u6bcf\u4e2a\u5bf9\u8c61\u90fd\u6709\u4e00\u4e2a <code>ob_refcnt<\/code>\u3002\u5f53\u5f15\u7528\u8ba1\u6570\u5f52\u96f6\u65f6\uff0c\u5185\u5b58\u7acb\u5373\u88ab\u91ca\u653e\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>  import sys\n  a = &#91;1, 2, 3]\n  print(sys.getrefcount(a))  # \u8f93\u51fa\u901a\u5e38\u4e3a 2 (a \u7684\u5f15\u7528 + getrefcount \u53c2\u6570\u5f15\u7528)\n  b = a\n  print(sys.getrefcount(a))  # \u8f93\u51fa 3\n  del b\n  print(sys.getrefcount(a))  # \u8f93\u51fa 2<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u5faa\u73af\u5f15\u7528\u4e0e\u5783\u573e\u56de\u6536 (GC)<\/strong>\uff1a\u5f15\u7528\u8ba1\u6570\u65e0\u6cd5\u89e3\u51b3\u5faa\u73af\u5f15\u7528\uff08\u5982 A \u5f15\u7528 B\uff0cB \u5f15\u7528 A\uff09\u3002Python \u5f15\u5165\u4e86<strong>\u5206\u4ee3\u5783\u573e\u56de\u6536\u673a\u5236<\/strong>\uff08Generational GC\uff09\uff0c\u5b9a\u671f\u626b\u63cf\u5e76\u6e05\u7406\u4e0d\u53ef\u8fbe\u7684\u5faa\u73af\u5f15\u7528\u5bf9\u8c61\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">3.2 \u5b57\u7b26\u4e32 (str) \u7684\u5e95\u5c42\u673a\u5236<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u4e0d\u53ef\u53d8\u6027 (Immutability)<\/strong>\uff1a\u5b57\u7b26\u4e32\u4e00\u65e6\u521b\u5efa\uff0c\u5176\u5185\u5b58\u4e2d\u7684\u503c\u4e0d\u80fd\u66f4\u6539\u3002\u4efb\u4f55\u4fee\u6539\u64cd\u4f5c\uff08\u5982\u62fc\u63a5\uff09\u90fd\u4f1a\u521b\u5efa\u65b0\u7684\u5b57\u7b26\u4e32\u5bf9\u8c61\u3002<\/li>\n\n\n\n<li><strong>\u5b57\u7b26\u4e32\u9a7b\u7559 (String Interning)<\/strong>\uff1a\u4e3a\u4e86\u8282\u7701\u5185\u5b58\uff0cPython \u4f1a\u81ea\u52a8\u9a7b\u7559\uff08\u7f13\u5b58\uff09\u7b26\u5408\u7279\u5b9a\u89c4\u5219\u7684\u77ed\u5b57\u7b26\u4e32\uff08\u4ec5\u5305\u542b\u5b57\u6bcd\u3001\u6570\u5b57\u3001\u4e0b\u5212\u7ebf\uff09\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>  a = \"hello_world\"\n  b = \"hello_world\"\n  print(a is b)  # True\uff0c\u6307\u5411\u540c\u4e00\u4e2a\u5185\u5b58\u5730\u5740\n\n  c = \"hello-world!\"\n  d = \"hello-world!\"\n  print(c is d)  # False (\u53d6\u51b3\u4e8e\u5177\u4f53 Python \u7248\u672c\u548c\u7f16\u8bd1\u5668\u4f18\u5316\uff0c\u901a\u5e38\u5305\u542b\u7279\u6b8a\u5b57\u7b26\u4e0d\u9a7b\u7559)<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>f-string (Python 3.6+)<\/strong>\uff1a\u4e0d\u4ec5\u8bed\u6cd5\u7b80\u6d01\uff0c\u800c\u4e14\u5728 C \u5c42\u9762\u76f4\u63a5\u7f16\u8bd1\u4e3a\u9ad8\u6548\u7684\u5b57\u7b26\u4e32\u62fc\u63a5\uff0c\u6027\u80fd\u4f18\u4e8e <code>%<\/code> \u683c\u5f0f\u5316\u548c <code>.format()<\/code>\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">3.3 \u6838\u5fc3\u6570\u636e\u7ed3\u6784\u5e95\u5c42\u5b9e\u73b0\u4e0e\u65f6\u95f4\u590d\u6742\u5ea6<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">\u5217\u8868 (List)<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u5e95\u5c42\u5b9e\u73b0<\/strong>\uff1a\u52a8\u6001\u6570\u7ec4 (Dynamic Array)\uff0c\u5b58\u50a8\u7684\u662f\u5bf9\u8c61\u7684<strong>\u6307\u9488<\/strong>\uff0c\u800c\u975e\u5bf9\u8c61\u672c\u8eab\u3002<\/li>\n\n\n\n<li><strong>\u6269\u5bb9\u673a\u5236<\/strong>\uff1a\u5f53\u5217\u8868\u6ee1\u65f6\uff0cPython \u4f1a\u5206\u914d\u4e00\u5757\u66f4\u5927\u7684\u8fde\u7eed\u5185\u5b58\uff08\u901a\u5e38\u8fc7\u5ea6\u5206\u914d\u7ea6 1\/8\uff09\uff0c\u5e76\u5c06\u65e7\u6307\u9488\u590d\u5236\u8fc7\u53bb\u3002<\/li>\n\n\n\n<li><strong>\u590d\u6742\u5ea6<\/strong>\uff1a<\/li>\n\n\n\n<li>\u7d22\u5f15\u8bbf\u95ee <code>lst[i]<\/code>\uff1a$O(1)$<\/li>\n\n\n\n<li>\u5c3e\u90e8\u8ffd\u52a0 <code>lst.append()<\/code>\uff1a\u5747\u644a $O(1)$<\/li>\n\n\n\n<li>\u5934\u90e8\u63d2\u5165 <code>lst.insert(0, x)<\/code>\uff1a$O(n)$ (\u9700\u8981\u79fb\u52a8\u6240\u6709\u540e\u7eed\u5143\u7d20)<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">\u5b57\u5178 (Dict) \u4e0e \u96c6\u5408 (Set)<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u5e95\u5c42\u5b9e\u73b0<\/strong>\uff1a\u54c8\u5e0c\u8868 (Hash Table)\u3002Python 3.6+ \u5bf9\u5b57\u5178\u8fdb\u884c\u4e86\u91cd\u6784\uff0c\u5206\u4e3a<strong>\u7a00\u758f\u7d22\u5f15\u6570\u7ec4<\/strong>\u548c<strong>\u7d27\u51d1\u6570\u636e\u6570\u7ec4<\/strong>\uff0c\u4e0d\u4ec5\u8282\u7701\u4e86\u5185\u5b58\uff0c\u8fd8<strong>\u4fdd\u8bc1\u4e86\u5b57\u5178\u7684\u63d2\u5165\u987a\u5e8f<\/strong>\u3002<\/li>\n\n\n\n<li><strong>\u54c8\u5e0c\u51b2\u7a81\u89e3\u51b3<\/strong>\uff1a\u5f00\u653e\u5bfb\u5740\u6cd5 (Open Addressing)\uff0c\u5177\u4f53\u4e3a\u4f2a\u968f\u673a\u63a2\u6d4b (Pseudo-random probing)\u3002<\/li>\n\n\n\n<li><strong>\u590d\u6742\u5ea6<\/strong>\uff1a<\/li>\n\n\n\n<li>\u67e5\u627e\u3001\u63d2\u5165\u3001\u5220\u9664\uff1a\u5e73\u5747 $O(1)$\uff0c\u6700\u574f $O(n)$ (\u53d1\u751f\u4e25\u91cd\u54c8\u5e0c\u51b2\u7a81\u65f6)\u3002<\/li>\n\n\n\n<li><strong>\u6ce8\u610f<\/strong>\uff1a\u5b57\u5178\u7684\u952e\u5fc5\u987b\u662f<strong>\u53ef\u54c8\u5e0c\u7684 (Hashable)<\/strong>\uff0c\u5373\u5177\u6709\u4e0d\u53d8\u7684\u54c8\u5e0c\u503c\uff08\u5982 <code>str<\/code>, <code>int<\/code>, <code>tuple<\/code>\uff09\uff0c\u53ef\u53d8\u5bf9\u8c61\uff08\u5982 <code>list<\/code>, <code>dict<\/code>\uff09\u4e0d\u80fd\u4f5c\u4e3a\u952e\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">3.4 \u63a8\u5bfc\u5f0f (Comprehensions) vs \u751f\u6210\u5668 (Generators)<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code># \u5217\u8868\u63a8\u5bfc\u5f0f\uff1a\u7acb\u5373\u8ba1\u7b97\u6240\u6709\u5143\u7d20\uff0c\u5360\u7528 O(n) \u5185\u5b58\nsquares_list = &#91;x**2 for x in range(1000000)] \n\n# \u751f\u6210\u5668\u8868\u8fbe\u5f0f\uff1a\u60f0\u6027\u6c42\u503c (Lazy Evaluation)\uff0c\u6bcf\u6b21 yield \u4e00\u4e2a\u503c\uff0c\u5360\u7528 O(1) \u5185\u5b58\nsquares_gen = (x**2 for x in range(1000000))\n\nprint(next(squares_gen))  # 0\nprint(next(squares_gen))  # 1<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6700\u4f73\u5b9e\u8df5<\/strong>\uff1a\u5904\u7406\u5927\u89c4\u6a21\u6570\u636e\u6d41\u6216\u53ea\u9700\u904d\u5386\u4e00\u6b21\u7684\u6570\u636e\u65f6\uff0c<strong>\u6c38\u8fdc\u4f18\u5148\u4f7f\u7528\u751f\u6210\u5668<\/strong>\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u7b2c\u56db\u90e8\u5206\uff1a\u51fd\u6570\u5f0f\u7f16\u7a0b\u4e0e\u9ad8\u7ea7\u7279\u6027<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">4.1 \u4e00\u7b49\u516c\u6c11\u51fd\u6570\u4e0e\u95ed\u5305 (Closures)<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728 Python \u4e2d\uff0c\u51fd\u6570\u662f\u5bf9\u8c61\uff0c\u53ef\u4ee5\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u3001\u4f5c\u4e3a\u8fd4\u56de\u503c\uff0c\u6216\u8d4b\u503c\u7ed9\u53d8\u91cf\u3002<br><strong>\u95ed\u5305<\/strong>\u662f\u6307\u4e00\u4e2a\u51fd\u6570\u8bb0\u4f4f\u4e86\u5176\u5b9a\u4e49\u65f6\u7684\u8bcd\u6cd5\u73af\u5883\uff0c\u5373\u4f7f\u8be5\u73af\u5883\u5df2\u7ecf\u4e0d\u5728\u5185\u5b58\u4e2d\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def make_multiplier(factor):\n    # factor \u662f\u81ea\u7531\u53d8\u91cf\uff0c\u88ab\u5185\u90e8\u51fd\u6570\u6355\u83b7\n    def multiplier(x):\n        return x * factor\n    return multiplier\n\ndouble = make_multiplier(2)\nprint(double(5))  # \u8f93\u51fa: 10\nprint(double.__closure__&#91;0].cell_contents)  # \u67e5\u770b\u6355\u83b7\u7684\u53d8\u91cf: 2<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">4.2 \u88c5\u9970\u5668 (Decorators) \u6df1\u5ea6\u89e3\u6790<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u88c5\u9970\u5668\u672c\u8d28\u4e0a\u662f\u4e00\u4e2a\u63a5\u53d7\u51fd\u6570\u4f5c\u4e3a\u53c2\u6570\u5e76\u8fd4\u56de\u65b0\u51fd\u6570\u7684\u9ad8\u9636\u51fd\u6570\u3002\u5e38\u7528\u4e8e\u65e5\u5fd7\u3001\u9274\u6743\u3001\u7f13\u5b58\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u57fa\u7840\u88c5\u9970\u5668<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import functools\nimport time\n\ndef timer(func):\n    @functools.wraps(func)  # \u5173\u952e\uff1a\u4fdd\u7559\u539f\u51fd\u6570\u7684\u5143\u6570\u636e (__name__, __doc__)\n    def wrapper(*args, **kwargs):\n        start_time = time.perf_counter()\n        result = func(*args, **kwargs)\n        end_time = time.perf_counter()\n        print(f\"\u51fd\u6570 {func.__name__} \u6267\u884c\u8017\u65f6: {end_time - start_time:.4f} \u79d2\")\n        return result\n    return wrapper\n\n@timer\ndef heavy_computation(n):\n    return sum(i * i for i in range(n))\n\nheavy_computation(10_000_000)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5e26\u53c2\u6570\u7684\u88c5\u9970\u5668<\/strong>\uff08\u9700\u8981\u4e09\u5c42\u5d4c\u5957\uff09\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def retry(max_attempts):\n    def decorator(func):\n        @functools.wraps(func)\n        def wrapper(*args, **kwargs):\n            for attempt in range(max_attempts):\n                try:\n                    return func(*args, **kwargs)\n                except Exception as e:\n                    print(f\"Attempt {attempt + 1} failed: {e}\")\n            raise RuntimeError(\"Max retries exceeded\")\n        return wrapper\n    return decorator\n\n@retry(max_attempts=3)\ndef unstable_api_call():\n    # \u6a21\u62df\u4e0d\u7a33\u5b9a\u64cd\u4f5c\n    pass<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">4.3 \u8fed\u4ee3\u5668\u534f\u8bae\u4e0e <code>yield<\/code><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u4efb\u4f55\u5b9e\u73b0\u4e86 <code>__iter__()<\/code> \u548c <code>__next__()<\/code> \u65b9\u6cd5\u7684\u5bf9\u8c61\u90fd\u662f\u8fed\u4ee3\u5668\u3002<code>yield<\/code> \u5173\u952e\u5b57\u5c06\u666e\u901a\u51fd\u6570\u8f6c\u53d8\u4e3a\u751f\u6210\u5668\u51fd\u6570\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def fibonacci(limit):\n    a, b = 0, 1\n    while a &lt; limit:\n        yield a\n        a, b = b, a + b\n\n# yield from (Python 3.3+) \u7528\u4e8e\u59d4\u6258\u751f\u6210\u5668\uff0c\u7b80\u5316\u5d4c\u5957\u751f\u6210\u5668\u7684\u7f16\u5199\ndef read_file_lines(file_path):\n    with open(file_path, 'r') as f:\n        yield from f  # \u7b49\u540c\u4e8e for line in f: yield line<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u7b2c\u4e94\u90e8\u5206\uff1a\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b (OOP) \u4e0e\u5143\u7f16\u7a0b<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">5.1 \u7c7b\u4e0e\u5b9e\u4f8b\u7684\u5185\u5b58\u5e03\u5c40<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>__dict__<\/code><\/strong>\uff1a\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cPython \u5bf9\u8c61\u7684\u5c5e\u6027\u5b58\u50a8\u5728\u4e00\u4e2a\u5b57\u5178\u4e2d\uff0c\u8fd9\u63d0\u4f9b\u4e86\u6781\u5927\u7684\u52a8\u6001\u6027\uff0c\u4f46\u6d88\u8017\u8f83\u591a\u5185\u5b58\u3002<\/li>\n\n\n\n<li><strong><code>__slots__<\/code><\/strong>\uff1a\u901a\u8fc7\u663e\u5f0f\u58f0\u660e\u5141\u8bb8\u7684\u5c5e\u6027\u540d\u79f0\uff0cPython \u4f1a\u963b\u6b62\u521b\u5efa <code>__dict__<\/code>\uff0c\u4ece\u800c\u5927\u5e45\u8282\u7701\u5185\u5b58\u5e76\u63d0\u9ad8\u5c5e\u6027\u8bbf\u95ee\u901f\u5ea6\uff08\u9002\u7528\u4e8e\u9700\u8981\u521b\u5efa\u6570\u767e\u4e07\u4e2a\u5b9e\u4f8b\u7684\u573a\u666f\uff09\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>  class Point:\n      __slots__ = &#91;'x', 'y']  # \u7981\u6b62\u52a8\u6001\u6dfb\u52a0\u5176\u4ed6\u5c5e\u6027\n      def __init__(self, x, y):\n          self.x = x\n          self.y = y<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">5.2 \u9b54\u672f\u65b9\u6cd5 (Dunder Methods) \u5b8c\u6574\u6307\u5357<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u9b54\u672f\u65b9\u6cd5\uff08\u53cc\u4e0b\u5212\u7ebf\u65b9\u6cd5\uff09\u5141\u8bb8\u81ea\u5b9a\u4e49\u7c7b\u53c2\u4e0e Python \u7684\u6838\u5fc3\u8bed\u6cd5\u64cd\u4f5c\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u6784\u9020\u4e0e\u6790\u6784<\/strong>\uff1a<code>__new__<\/code> (\u63a7\u5236\u5bf9\u8c61\u521b\u5efa\uff0c\u5e38\u7528\u4e8e\u5355\u4f8b\u6a21\u5f0f), <code>__init__<\/code> (\u521d\u59cb\u5316), <code>__del__<\/code> (\u6790\u6784\uff0c\u4f46\u4e0d\u4fdd\u8bc1\u7acb\u5373\u6267\u884c)\u3002<\/li>\n\n\n\n<li><strong>\u5b57\u7b26\u4e32\u8868\u793a<\/strong>\uff1a<code>__str__<\/code> (\u9762\u5411\u7528\u6237\uff0c<code>print()<\/code> \u8c03\u7528), <code>__repr__<\/code> (\u9762\u5411\u5f00\u53d1\u8005\uff0c\u8c03\u8bd5\u65f6\u4f7f\u7528\uff0c\u5e94\u5c3d\u53ef\u80fd\u8fd4\u56de\u53ef\u91cd\u5efa\u5bf9\u8c61\u7684\u4ee3\u7801)\u3002<\/li>\n\n\n\n<li><strong>\u5bb9\u5668\u884c\u4e3a<\/strong>\uff1a<code>__len__<\/code>, <code>__getitem__<\/code>, <code>__setitem__<\/code>, <code>__contains__<\/code> (\u652f\u6301 <code>in<\/code> \u64cd\u4f5c\u7b26)\u3002<\/li>\n\n\n\n<li><strong>\u4e0a\u4e0b\u6587\u7ba1\u7406\u5668<\/strong>\uff1a<code>__enter__<\/code>, <code>__exit__<\/code> (\u652f\u6301 <code>with<\/code> \u8bed\u53e5)\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>  class DatabaseConnection:\n      def __enter__(self):\n          self.conn = connect_to_db()\n          return self.conn\n\n      def __exit__(self, exc_type, exc_val, exc_tb):\n          self.conn.close()\n          if exc_type is not None:\n              print(f\"\u53d1\u751f\u5f02\u5e38: {exc_val}\")\n          return False  # \u4e0d\u6291\u5236\u5f02\u5e38<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">5.3 \u591a\u91cd\u7ee7\u627f\u4e0e MRO (\u65b9\u6cd5\u89e3\u6790\u987a\u5e8f)<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Python \u652f\u6301\u591a\u91cd\u7ee7\u627f\uff0c\u4f7f\u7528 <strong>C3 \u7ebf\u6027\u5316\u7b97\u6cd5 (C3 Linearization)<\/strong> \u6765\u51b3\u5b9a\u65b9\u6cd5\u8c03\u7528\u7684\u987a\u5e8f\uff0c\u907f\u514d\u83f1\u5f62\u7ee7\u627f\u95ee\u9898\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class A:\n    def process(self): print(\"A\")\n\nclass B(A):\n    def process(self): \n        super().process()\n        print(\"B\")\n\nclass C(A):\n    def process(self): \n        super().process()\n        print(\"C\")\n\nclass D(B, C):\n    def process(self): \n        super().process()\n        print(\"D\")\n\nd = D()\nd.process()\n# \u8f93\u51fa\u987a\u5e8f: A -&gt; C -&gt; B -&gt; D\n# \u53ef\u901a\u8fc7 D.mro() \u67e5\u770b\u89e3\u6790\u987a\u5e8f: &#91;&lt;class 'D'&gt;, &lt;class 'B'&gt;, &lt;class 'C'&gt;, &lt;class 'A'&gt;, &lt;class 'object'&gt;]<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">5.4 \u5143\u7c7b (Metaclasses) \u7b80\u4ecb<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u201c\u7c7b\u662f\u521b\u5efa\u5b9e\u4f8b\u7684\u6a21\u677f\uff0c\u800c\u5143\u7c7b\u662f\u521b\u5efa\u7c7b\u7684\u6a21\u677f\u201d\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cPython \u4e2d\u6240\u6709\u7c7b\u7684\u5143\u7c7b\u90fd\u662f <code>type<\/code>\u3002<br><strong>\u5e94\u7528\u573a\u666f<\/strong>\uff1aORM \u6846\u67b6\uff08\u5982 Django \u7684 Models\uff09\u3001API \u6ce8\u518c\u8868\u3001\u5f3a\u5236\u4ee3\u7801\u89c4\u8303\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class SingletonMeta(type):\n    _instances = {}\n    def __call__(cls, *args, **kwargs):\n        if cls not in cls._instances:\n            cls._instances&#91;cls] = super().__call__(*args, **kwargs)\n        return cls._instances&#91;cls]\n\nclass Database(metaclass=SingletonMeta):\n    pass\n\ndb1 = Database()\ndb2 = Database()\nprint(db1 is db2)  # True<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u7b2c\u516d\u90e8\u5206\uff1a\u5e76\u53d1\u7f16\u7a0b\u4e0e\u5f02\u6b65 I\/O (Asyncio)<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">6.1 \u591a\u7ebf\u7a0b (Threading) vs \u591a\u8fdb\u7a0b (Multiprocessing)<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th class=\"has-text-align-left\" data-align=\"left\">\u7279\u6027<\/th><th class=\"has-text-align-left\" data-align=\"left\"><code>threading<\/code> (\u591a\u7ebf\u7a0b)<\/th><th class=\"has-text-align-left\" data-align=\"left\"><code>multiprocessing<\/code> (\u591a\u8fdb\u7a0b)<\/th><\/tr><\/thead><tbody><tr><td class=\"has-text-align-left\" data-align=\"left\"><strong>\u5185\u5b58\u5171\u4eab<\/strong><\/td><td class=\"has-text-align-left\" data-align=\"left\">\u5171\u4eab\u540c\u4e00\u8fdb\u7a0b\u7684\u5185\u5b58\u7a7a\u95f4<\/td><td class=\"has-text-align-left\" data-align=\"left\">\u72ec\u7acb\u7684\u5185\u5b58\u7a7a\u95f4 (\u9700\u901a\u8fc7 Queue\/Pipe \u901a\u4fe1)<\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\"><strong>GIL \u9650\u5236<\/strong><\/td><td class=\"has-text-align-left\" data-align=\"left\">\u53d7 GIL \u9650\u5236\uff0c\u65e0\u6cd5\u5e76\u884c\u6267\u884c CPU \u5bc6\u96c6\u578b Python \u4ee3\u7801<\/td><td class=\"has-text-align-left\" data-align=\"left\">\u6bcf\u4e2a\u8fdb\u7a0b\u6709\u72ec\u7acb\u7684 Python \u89e3\u91ca\u5668\u548c GIL\uff0c\u53ef\u771f\u6b63\u5229\u7528\u591a\u6838<\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\"><strong>\u5f00\u9500<\/strong><\/td><td class=\"has-text-align-left\" data-align=\"left\">\u521b\u5efa\u548c\u5207\u6362\u5f00\u9500\u5c0f<\/td><td class=\"has-text-align-left\" data-align=\"left\">\u521b\u5efa\u548c\u5207\u6362\u5f00\u9500\u5927 (\u6d89\u53ca OS \u8fdb\u7a0b\u8c03\u5ea6)<\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\"><strong>\u9002\u7528\u573a\u666f<\/strong><\/td><td class=\"has-text-align-left\" data-align=\"left\">I\/O \u5bc6\u96c6\u578b (\u7f51\u7edc\u722c\u866b\u3001\u6587\u4ef6\u8bfb\u5199)<\/td><td class=\"has-text-align-left\" data-align=\"left\">CPU \u5bc6\u96c6\u578b (\u56fe\u50cf\u5904\u7406\u3001\u5927\u89c4\u6a21\u6570\u503c\u8ba1\u7b97)<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">6.2 \u5f02\u6b65\u7f16\u7a0b (Asyncio) \u6838\u5fc3\u6982\u5ff5<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><code>asyncio<\/code> \u662f Python 3.4+ \u5f15\u5165\u7684\u6807\u51c6\u5e93\uff0c\u7528\u4e8e\u7f16\u5199\u5355\u7ebf\u7a0b\u5e76\u53d1\u4ee3\u7801\u3002\u5b83\u57fa\u4e8e<strong>\u4e8b\u4ef6\u5faa\u73af (Event Loop)<\/strong>\u3001<strong>\u534f\u7a0b (Coroutines)<\/strong>\u3001<strong>\u4efb\u52a1 (Tasks)<\/strong> \u548c <strong>Future<\/strong> \u6784\u5efa\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import asyncio\nimport aiohttp\nimport time\n\nasync def fetch_data(session, url):\n    print(f\"\u5f00\u59cb\u8bf7\u6c42: {url}\")\n    async with session.get(url) as response:\n        # await \u6302\u8d77\u5f53\u524d\u534f\u7a0b\uff0c\u8ba9\u51fa\u63a7\u5236\u6743\u7ed9\u4e8b\u4ef6\u5faa\u73af\uff0c\u76f4\u5230 I\/O \u5b8c\u6210\n        data = await response.text()\n        print(f\"\u5b8c\u6210\u8bf7\u6c42: {url}, \u957f\u5ea6: {len(data)}\")\n        return len(data)\n\nasync def main():\n    urls = &#91;\n        \"https:\/\/httpbin.org\/delay\/1\",\n        \"https:\/\/httpbin.org\/delay\/2\",\n        \"https:\/\/httpbin.org\/delay\/1\"\n    ]\n\n    start_time = time.perf_counter()\n\n    # \u521b\u5efa\u5355\u4e00\u7684 aiohttp \u4f1a\u8bdd\uff0c\u590d\u7528 TCP \u8fde\u63a5\n    async with aiohttp.ClientSession() as session:\n        # \u521b\u5efa\u4efb\u52a1\u5217\u8868\n        tasks = &#91;fetch_data(session, url) for url in urls]\n        # asyncio.gather \u5e76\u53d1\u6267\u884c\u6240\u6709\u4efb\u52a1\uff0c\u5e76\u7b49\u5f85\u5b83\u4eec\u5168\u90e8\u5b8c\u6210\n        results = await asyncio.gather(*tasks)\n\n    end_time = time.perf_counter()\n    print(f\"\u603b\u8017\u65f6: {end_time - start_time:.2f} \u79d2\")\n    print(f\"\u7ed3\u679c: {results}\")\n\n# Python 3.7+ \u63a8\u8350\u8fd0\u884c\u65b9\u5f0f\nif __name__ == \"__main__\":\n    asyncio.run(main())<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5173\u952e\u539f\u5219<\/strong>\uff1a\u5728 <code>async<\/code> \u51fd\u6570\u4e2d\uff0c<strong>\u7edd\u5bf9\u4e0d\u80fd<\/strong>\u8c03\u7528\u963b\u585e\u7684\u540c\u6b65\u4ee3\u7801\uff08\u5982 <code>time.sleep()<\/code>, <code>requests.get()<\/code>\uff09\uff0c\u5426\u5219\u4f1a\u963b\u585e\u6574\u4e2a\u4e8b\u4ef6\u5faa\u73af\u3002\u5fc5\u987b\u4f7f\u7528\u5bf9\u5e94\u7684\u5f02\u6b65\u5e93\uff08\u5982 <code>asyncio.sleep()<\/code>, <code>aiohttp<\/code>\uff09\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u7b2c\u4e03\u90e8\u5206\uff1a\u5f02\u5e38\u5904\u7406\u3001\u8c03\u8bd5\u4e0e\u6d4b\u8bd5\u9a71\u52a8\u5f00\u53d1 (TDD)<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">7.1 \u5f02\u5e38\u5c42\u6b21\u7ed3\u6784\u4e0e\u6700\u4f73\u5b9e\u8df5<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Python \u7684\u5f02\u5e38\u90fd\u7ee7\u627f\u81ea <code>BaseException<\/code>\u3002\u81ea\u5b9a\u4e49\u5f02\u5e38\u5e94\u7ee7\u627f\u81ea <code>Exception<\/code>\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class InsufficientFundsError(Exception):\n    \"\"\"\u81ea\u5b9a\u4e49\u4e1a\u52a1\u5f02\u5e38\"\"\"\n    def __init__(self, balance, amount):\n        self.balance = balance\n        self.amount = amount\n        super().__init__(f\"\u4f59\u989d\u4e0d\u8db3: \u5f53\u524d\u4f59\u989d {balance}, \u5c1d\u8bd5\u6263\u9664 {amount}\")\n\ndef withdraw(balance, amount):\n    if amount &gt; balance:\n        raise InsufficientFundsError(balance, amount)\n    return balance - amount\n\ntry:\n    withdraw(100, 150)\nexcept InsufficientFundsError as e:\n    print(f\"\u6355\u83b7\u5230\u4e1a\u52a1\u5f02\u5e38: {e}\")\nexcept Exception as e:\n    # \u6355\u83b7\u6240\u6709\u5176\u4ed6\u5f02\u5e38\uff0c\u4f5c\u4e3a\u6700\u540e\u7684\u9632\u7ebf\n    print(f\"\u53d1\u751f\u672a\u77e5\u9519\u8bef: {e}\")\n    # \u5728\u751f\u4ea7\u73af\u5883\u4e2d\uff0c\u8fd9\u91cc\u5e94\u8bb0\u5f55\u65e5\u5fd7 (logging.error)\nfinally:\n    print(\"\u6e05\u7406\u8d44\u6e90\u64cd\u4f5c\uff08\u5982\u5173\u95ed\u6587\u4ef6\u3001\u91ca\u653e\u9501\uff09\")<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6700\u4f73\u5b9e\u8df5<\/strong>\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u6355\u83b7\u5177\u4f53\u5f02\u5e38<\/strong>\uff1a\u907f\u514d\u4f7f\u7528\u88f8 <code>except:<\/code>\uff0c\u8fd9\u4f1a\u6355\u83b7 <code>KeyboardInterrupt<\/code> \u7b49\u7cfb\u7edf\u5f02\u5e38\uff0c\u63a9\u76d6\u771f\u5b9e\u9519\u8bef\u3002<\/li>\n\n\n\n<li><strong>EAFP \u539f\u5219<\/strong>\uff1a(Easier to Ask for Forgiveness than Permission) \u201c\u8bf7\u6c42\u5bbd\u6055\u6bd4\u8bf7\u6c42\u8bb8\u53ef\u66f4\u5bb9\u6613\u201d\u3002\u5728 Python \u4e2d\uff0c\u76f4\u63a5\u5c1d\u8bd5\u64cd\u4f5c\u5e76\u6355\u83b7\u5f02\u5e38\uff0c\u901a\u5e38\u6bd4\u4e8b\u5148\u68c0\u67e5\u6761\u4ef6 (LBYL) \u66f4\u5177 Pythonic \u98ce\u683c\u4e14\u66f4\u9ad8\u6548\u3002<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">7.2 \u8c03\u8bd5\u6280\u5de7<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>pdb<\/code> (Python Debugger)<\/strong>\uff1a\u5728\u4ee3\u7801\u4e2d\u63d2\u5165 <code>import pdb; pdb.set_trace()<\/code> (Python 3.7+ \u53ef\u76f4\u63a5\u4f7f\u7528 <code>breakpoint()<\/code>)\uff0c\u53ef\u8fdb\u5165\u4ea4\u4e92\u5f0f\u8c03\u8bd5\u73af\u5883\uff0c\u652f\u6301\u5355\u6b65\u6267\u884c (<code>n<\/code>)\u3001\u8fdb\u5165\u51fd\u6570 (<code>s<\/code>)\u3001\u67e5\u770b\u53d8\u91cf (<code>p var<\/code>)\u3002<\/li>\n\n\n\n<li><strong><code>logging<\/code> \u6a21\u5757<\/strong>\uff1a\u6c38\u8fdc\u4e0d\u8981\u5728\u751f\u4ea7\u4ee3\u7801\u4e2d\u4f7f\u7528 <code>print<\/code> \u8fdb\u884c\u8c03\u8bd5\u3002\u4f7f\u7528 <code>logging<\/code> \u53ef\u4ee5\u63a7\u5236\u65e5\u5fd7\u7ea7\u522b (DEBUG, INFO, WARNING, ERROR, CRITICAL)\u3001\u8f93\u51fa\u683c\u5f0f\u548c\u76ee\u6807\uff08\u6587\u4ef6\u3001\u63a7\u5236\u53f0\u3001\u8fdc\u7a0b\u670d\u52a1\u5668\uff09\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">7.3 \u6d4b\u8bd5\u9a71\u52a8\u5f00\u53d1 (TDD) \u4e0e <code>pytest<\/code><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><code>pytest<\/code> \u662f\u76ee\u524d Python \u793e\u533a\u6700\u6d41\u884c\u7684\u6d4b\u8bd5\u6846\u67b6\uff0c\u4ee5\u5176\u7b80\u6d01\u7684\u65ad\u8a00\u548c\u5f3a\u5927\u7684 fixture \u673a\u5236\u8457\u79f0\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># test_math_ops.py\nimport pytest\n\ndef add(a, b):\n    return a + b\n\ndef test_add_positive_numbers():\n    assert add(2, 3) == 5\n\ndef test_add_negative_numbers():\n    assert add(-1, -1) == -2\n\n# \u6d4b\u8bd5\u5f02\u5e38\u629b\u51fa\ndef test_divide_by_zero():\n    with pytest.raises(ZeroDivisionError):\n        1 \/ 0\n\n# Fixture \u793a\u4f8b\uff1a\u4e3a\u6d4b\u8bd5\u63d0\u4f9b\u53ef\u590d\u7528\u7684\u524d\u7f6e\u6761\u4ef6\n@pytest.fixture\ndef sample_data():\n    return {\"name\": \"Alice\", \"age\": 30}\n\ndef test_sample_data_processing(sample_data):\n    assert sample_data&#91;\"name\"] == \"Alice\"<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c\u6d4b\u8bd5\uff1a<code>pytest test_math_ops.py -v<\/code><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u7b2c\u516b\u90e8\u5206\uff1a\u6027\u80fd\u4f18\u5316\u3001\u7c7b\u578b\u63d0\u793a\u4e0e\u4ee3\u7801\u89c4\u8303<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">8.1 PEP 8 \u4e0e\u4ee3\u7801\u89c4\u8303<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>PEP 8<\/strong> \u662f Python \u7684\u5b98\u65b9\u98ce\u683c\u6307\u5357\u3002<\/li>\n\n\n\n<li><strong>\u81ea\u52a8\u5316\u5de5\u5177<\/strong>\uff1a<\/li>\n\n\n\n<li><strong>\u683c\u5f0f\u5316<\/strong>\uff1a<code>Black<\/code> (\u4e0d\u59a5\u534f\u7684\u4ee3\u7801\u683c\u5f0f\u5316\u5668), <code>Ruff<\/code> (\u6781\u901f\u7684 Rust \u7f16\u5199\u7684 linter \u548c formatter\uff0c\u73b0\u4ee3\u9996\u9009)\u3002<\/li>\n\n\n\n<li><strong>\u9759\u6001\u68c0\u67e5<\/strong>\uff1a<code>Flake8<\/code>, <code>Pylint<\/code>\u3002<\/li>\n\n\n\n<li><strong>\u547d\u540d\u7ea6\u5b9a<\/strong>\uff1a<\/li>\n\n\n\n<li>\u53d8\u91cf\/\u51fd\u6570\uff1a<code>snake_case<\/code><\/li>\n\n\n\n<li>\u7c7b\u540d\uff1a<code>CamelCase<\/code><\/li>\n\n\n\n<li>\u5e38\u91cf\uff1a<code>UPPER_SNAKE_CASE<\/code><\/li>\n\n\n\n<li>\u79c1\u6709\u5c5e\u6027\uff1a<code>_single_leading_underscore<\/code> (\u7ea6\u5b9a\u4fd7\u6210\uff0c\u975e\u5f3a\u5236)<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">8.2 \u7c7b\u578b\u63d0\u793a (Type Hints, PEP 484)<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Python 3.5+ \u5f15\u5165\u4e86\u7c7b\u578b\u63d0\u793a\u3002\u5b83<strong>\u4e0d\u4f1a<\/strong>\u5728\u8fd0\u884c\u65f6\u5f3a\u5236\u6267\u884c\uff0c\u4f46\u53ef\u4ee5\u88ab\u9759\u6001\u7c7b\u578b\u68c0\u67e5\u5668\uff08\u5982 <code>mypy<\/code>\uff09\u6216 IDE \u7528\u4e8e\u6355\u83b7\u9519\u8bef\u548c\u63d0\u9ad8\u4ee3\u7801\u53ef\u8bfb\u6027\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from typing import List, Dict, Optional, Union\n\ndef process_users(users: List&#91;Dict&#91;str, Union&#91;str, int]]], limit: Optional&#91;int] = None) -&gt; List&#91;str]:\n    \"\"\"\n    \u5904\u7406\u7528\u6237\u5217\u8868\uff0c\u8fd4\u56de\u7528\u6237\u540d\u3002\n    :param users: \u7528\u6237\u5b57\u5178\u5217\u8868\n    :param limit: \u53ef\u9009\u7684\u5904\u7406\u6570\u91cf\u9650\u5236\n    :return: \u7528\u6237\u540d\u5217\u8868\n    \"\"\"\n    if limit is not None:\n        users = users&#91;:limit]\n    return &#91;user&#91;\"name\"] for user in users]\n\n# Python 3.10+ \u53ef\u4ee5\u4f7f\u7528\u66f4\u7b80\u6d01\u7684\u8bed\u6cd5:\n# def process_users(users: list&#91;dict&#91;str, str | int]], limit: int | None = None) -&gt; list&#91;str]:<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5efa\u8bae<\/strong>\uff1a\u5728\u65b0\u9879\u76ee\u4e2d\uff0c\u542f\u7528 <code>mypy --strict<\/code> \u5e76\u9010\u6b65\u4e3a\u4ee3\u7801\u5e93\u6dfb\u52a0\u7c7b\u578b\u6ce8\u89e3\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">8.3 \u6027\u80fd\u5206\u6790 (Profiling)<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0d\u8981\u76f2\u76ee\u4f18\u5316\u3002\u5148\u6d4b\u91cf\uff0c\u518d\u4f18\u5316\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>timeit<\/code><\/strong>\uff1a\u7528\u4e8e\u5fae\u57fa\u51c6\u6d4b\u8bd5 (Micro-benchmarking) \u5c0f\u6bb5\u4ee3\u7801\u7684\u6267\u884c\u65f6\u95f4\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>  python -m timeit '\"-\".join(str(n) for n in range(100))'<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>cProfile<\/code><\/strong>\uff1a\u7528\u4e8e\u5b8f\u89c2\u6027\u80fd\u5206\u6790\uff0c\u627e\u51fa\u7a0b\u5e8f\u4e2d\u7684\u6027\u80fd\u74f6\u9888\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>  python -m cProfile -s cumtime my_script.py<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">(\u6309\u7d2f\u8ba1\u65f6\u95f4 <code>cumtime<\/code> \u6392\u5e8f\u8f93\u51fa\uff0c\u5feb\u901f\u5b9a\u4f4d\u6700\u8017\u65f6\u7684\u51fd\u6570)\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u9644\u5f55\uff1a\u94fe\u63a5\u4e0e\u8d44\u6e90\u6c47\u603b<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e3a\u4e86\u6ee1\u8db3\u60a8\u7684\u8981\u6c42\uff0c\u4ee5\u4e0b\u662f\u7cbe\u5fc3\u6574\u7406\u7684\u5b66\u4e60\u8d44\u6e90\u7f51\u7edc\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udcda \u53c2\u8003\u94fe\u63a5 (Reference Links)<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><em>\u8fd9\u4e9b\u662f Python \u8bed\u8a00\u89c4\u8303\u548c\u5b98\u65b9\u8bbe\u8ba1\u7684\u6743\u5a01\u6765\u6e90\u3002<\/em><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><a href=\"https:\/\/docs.python.org\/3\/\">Python 3 \u5b98\u65b9\u6587\u6863 (The Python Standard Library)<\/a> &#8211; \u6700\u6743\u5a01\u3001\u6700\u5168\u9762\u7684\u53c2\u8003\u8d44\u6599\u3002<\/li>\n\n\n\n<li><a href=\"https:\/\/peps.python.org\/pep-0008\/\">PEP 8 &#8212; Style Guide for Python Code<\/a> &#8211; \u5b98\u65b9\u4ee3\u7801\u98ce\u683c\u6307\u5357\u3002<\/li>\n\n\n\n<li><a href=\"https:\/\/peps.python.org\/pep-0484\/\">PEP 484 &#8212; Type Hints<\/a> &#8211; Python \u7c7b\u578b\u63d0\u793a\u7684\u5b98\u65b9\u89c4\u8303\u3002<\/li>\n\n\n\n<li><a href=\"https:\/\/peps.python.org\/pep-0703\/\">PEP 703 &#8212; Making the Global Interpreter Lock Optional in CPython<\/a> &#8211; \u5173\u4e8e\u672a\u6765\u79fb\u9664 GIL \u7684\u91cd\u8981\u63d0\u6848 (Python 3.13+)\u3002<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83c\udf10 \u51fa\u7ad9\u94fe\u63a5 (Outbound Links)<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><em>\u8fd9\u4e9b\u662f\u5916\u90e8\u9ad8\u8d28\u91cf\u793e\u533a\u3001\u5de5\u5177\u548c\u8fdb\u9636\u5b66\u4e60\u8d44\u6e90\u3002<\/em><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><a href=\"https:\/\/realpython.com\/\">Real Python<\/a> &#8211; \u63d0\u4f9b\u6700\u4f18\u8d28\u3001\u6700\u6613\u61c2\u7684 Python \u8fdb\u9636\u6559\u7a0b\u548c\u6700\u4f73\u5b9e\u8df5\u6587\u7ae0\u3002<\/li>\n\n\n\n<li><a href=\"https:\/\/www.oreilly.com\/library\/view\/fluent-python-2nd\/9781492056348\/\">Fluent Python (\u4e66\u7c4d\u8d44\u6e90)<\/a> &#8211; Luciano Ramalho \u8457\uff0c\u88ab\u8a89\u4e3a Python \u8fdb\u9636\u7684\u201c\u5723\u7ecf\u201d\uff0c\u6df1\u5165\u8bb2\u89e3 Python \u6570\u636e\u6a21\u578b\u3002<\/li>\n\n\n\n<li><a href=\"https:\/\/github.com\/astral-sh\/ruff\">Ruff (Astral)<\/a> &#8211; \u73b0\u4ee3 Python \u9879\u76ee\u9996\u9009\u7684\u6781\u901f Linter \u548c Formatter (Rust \u7f16\u5199)\u3002<\/li>\n\n\n\n<li><a href=\"https:\/\/www.fullstackpython.com\/\">Full Stack Python<\/a> &#8211; \u5168\u9762\u4ecb\u7ecd Python \u5728 Web \u5f00\u53d1\u3001DevOps\u3001\u6570\u636e\u5206\u6790\u7b49\u9886\u57df\u7684\u5e94\u7528\u6808\u3002<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udd17 \u7ad9\u5185\u94fe\u63a5 (Internal Links)<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><em>\u6a21\u62df\u672c\u7ad9\/\u672c\u6307\u5357\u5185\u7684\u5feb\u901f\u5bfc\u822a\u951a\u70b9\uff0c\u65b9\u4fbf\u60a8\u56de\u987e\u7279\u5b9a\u7ae0\u8282\u3002<\/em><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"#13-\u5168\u5c40\u89e3\u91ca\u5668\u9501-gil-\u7684\u6df1\u5ea6\u89e3\u6790\">\u8fd4\u56de\uff1a\u5168\u5c40\u89e3\u91ca\u5668\u9501 (GIL) \u6df1\u5ea6\u89e3\u6790<\/a><\/li>\n\n\n\n<li><a href=\"#22-\u73b0\u4ee3\u4f9d\u8d56\u7ba1\u7406\u5de5\u5177\u5bf9\u6bd4\">\u8fd4\u56de\uff1a\u73b0\u4ee3\u4f9d\u8d56\u7ba1\u7406\u5de5\u5177\u5bf9\u6bd4<\/a><\/li>\n\n\n\n<li><a href=\"#33-\u6838\u5fc3\u6570\u636e\u7ed3\u6784\u5e95\u5c42\u5b9e\u73b0\u4e0e\u65f6\u95f4\u590d\u6742\u5ea6\">\u8fd4\u56de\uff1a\u5b57\u5178\u4e0e\u96c6\u5408\u5e95\u5c42\u5b9e\u73b0<\/a><\/li>\n\n\n\n<li><a href=\"#42-\u88c5\u9970\u5668-decorators-\u6df1\u5ea6\u89e3\u6790\">\u8fd4\u56de\uff1a\u88c5\u9970\u5668\u6df1\u5ea6\u89e3\u6790<\/a><\/li>\n\n\n\n<li><a href=\"#62-\u5f02\u6b65\u7f16\u7a0b-asyncio-\u6838\u5fc3\u6982\u5ff5\">\u8fd4\u56de\uff1a\u5f02\u6b65\u7f16\u7a0b (Asyncio) \u6838\u5fc3\u6982\u5ff5<\/a><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udcd6 \u76f8\u5173\u9605\u8bfb (Further Reading)<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><em>\u5982\u679c\u60a8\u60f3\u7ee7\u7eed\u6df1\u5165\uff0c\u5efa\u8bae\u6309\u4ee5\u4e0b\u987a\u5e8f\u9605\u8bfb\uff1a<\/em><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u300a\u6d41\u7545\u7684 Python (Fluent Python)\u300b<\/strong>\uff1a\u6df1\u5165\u7406\u89e3 Python \u7684\u6570\u636e\u6a21\u578b\u3001\u5143\u7f16\u7a0b\u548c\u5e76\u53d1\uff0c\u662f\u8131\u79bb\u201c\u65b0\u624b\u201d\u9636\u6bb5\u7684\u5fc5\u7ecf\u4e4b\u8def\u3002<\/li>\n\n\n\n<li><strong>\u300aEffective Python: \u7f16\u5199\u9ad8\u8d28\u91cf Python \u4ee3\u7801\u7684 90 \u4e2a\u6709\u6548\u65b9\u6cd5\u300b<\/strong>\uff1a\u63d0\u4f9b\u5b9e\u7528\u7684\u3001\u53ef\u76f4\u63a5\u5e94\u7528\u4e8e\u751f\u4ea7\u73af\u5883\u7684\u7f16\u7801\u6280\u5de7\u548c\u907f\u5751\u6307\u5357\u3002<\/li>\n\n\n\n<li><strong>\u300aPython Cookbook\u300b<\/strong>\uff1a\u6309\u4e3b\u9898\u5206\u7c7b\u7684\u9ad8\u7ea7\u7f16\u7a0b\u6280\u5de7\u98df\u8c31\uff0c\u9002\u5408\u9047\u5230\u5177\u4f53\u95ee\u9898\u65f6\u67e5\u9605\u3002<\/li>\n\n\n\n<li><strong>CPython \u6e90\u7801\u9605\u8bfb<\/strong>\uff1a\u5bf9\u4e8e\u5e0c\u671b\u7406\u89e3 Python \u5e95\u5c42\u673a\u5236\u7684\u5f00\u53d1\u8005\uff0c\u9605\u8bfb <a href=\"https:\/\/github.com\/python\/cpython\">CPython GitHub \u4ed3\u5e93<\/a> \u4e2d\u7684 <code>Objects\/<\/code> \u548c <code>Python\/<\/code> \u76ee\u5f55\u662f\u7ec8\u6781\u6311\u6218\u3002<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p class=\"wp-block-paragraph\"><em>\u6ce8\uff1a\u7531\u4e8e\u5355\u6b21 AI \u751f\u6210\u7684 Token \u9650\u5236\uff0c\u672c\u6587\u5df2\u5c3d\u53ef\u80fd\u5728\u7cfb\u7edf\u5141\u8bb8\u7684\u6700\u5927\u957f\u5ea6\u5185\uff0c\u63d0\u4f9b\u4e86\u6700\u9ad8\u5bc6\u5ea6\u3001\u6700\u6df1\u5ea6\u7684 Python 3 \u77e5\u8bc6\u4f53\u7cfb\u3002\u5982\u679c\u60a8\u9700\u8981\u9488\u5bf9\u4e0a\u8ff0\u4efb\u4f55\u4e00\u4e2a\u7ae0\u8282\uff08\u4f8b\u5982\uff1a\u201c\u8be6\u7ec6\u5c55\u5f00 Asyncio \u7684\u5e95\u5c42 Event Loop \u5b9e\u73b0\u201d \u6216 \u201c\u63d0\u4f9b\u5b8c\u6574\u7684 Django\/FastAPI \u9879\u76ee\u67b6\u6784\u793a\u4f8b\u201d\uff09\u8fdb\u884c\u4e07\u5b57\u7ea7\u522b\u7684\u5355\u72ec\u6269\u5c55\uff0c\u8bf7\u968f\u65f6\u544a\u8bc9\u6211\uff0c\u6211\u5c06\u4e3a\u60a8\u751f\u6210\u8be5\u4e3b\u9898\u7684\u4e13\u5c5e\u6df1\u5ea6\u957f\u6587\u3002<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u76ee\u5f55 (\u7ad9\u5185\u5bfc\u822a) \u7b2c\u4e00\u90e8\u5206\uff1aPython \u54f2\u5b66\u3001\u5386\u53f2\u4e0e\u73b0\u4ee3\u751f\u6001 1.1 Python \u4e4b\u7985 (The Zen [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-12","post","type-post","status-publish","format-standard","hentry","category-python-3-"],"_links":{"self":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/12","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/comments?post=12"}],"version-history":[{"count":1,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/12\/revisions"}],"predecessor-version":[{"id":13,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/12\/revisions\/13"}],"wp:attachment":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/media?parent=12"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/categories?post=12"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/tags?post=12"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}