{"id":950650,"date":"2024-12-27T00:41:12","date_gmt":"2024-12-26T16:41:12","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/950650.html"},"modified":"2024-12-27T00:41:15","modified_gmt":"2024-12-26T16:41:15","slug":"python-%e6%a8%a1%e5%9d%97-%e5%a6%82%e4%bd%95-doc","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/950650.html","title":{"rendered":"python \u6a21\u5757 \u5982\u4f55 doc"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25085004\/77bf360a-c3b5-431d-94e9-a007bbe40b0c.webp\" alt=\"python \u6a21\u5757 \u5982\u4f55 doc\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\uff0c\u7f16\u5199\u6a21\u5757\u7684\u6587\u6863\u662f\u901a\u8fc7docstring\u6765\u5b9e\u73b0\u7684\u3001docstring\u662f\u4e00\u4e2a\u7528\u4e8e\u63cf\u8ff0\u6a21\u5757\u3001\u7c7b\u3001\u65b9\u6cd5\u548c\u51fd\u6570\u7684\u5b57\u7b26\u4e32\uff0c\u5b83\u63d0\u4f9b\u4e86\u4e00\u4e2a\u6807\u51c6\u7684\u65b9\u6cd5\u6765\u8bb0\u5f55Python\u4ee3\u7801\u3002\u8981\u7f16\u5199\u6a21\u5757\u7684\u6587\u6863\uff0c\u4f60\u53ef\u4ee5\u5728\u6a21\u5757\u7684\u5f00\u5934\u4f7f\u7528docstring\u6765\u63cf\u8ff0\u6a21\u5757\u7684\u529f\u80fd\u3001\u4f7f\u7528\u65b9\u6cd5\u3001\u53c2\u6570\u548c\u8fd4\u56de\u503c\u3002\u8be6\u7ec6\u7684\u6a21\u5757\u6587\u6863\u6709\u52a9\u4e8e\u5176\u4ed6\u5f00\u53d1\u8005\u7406\u89e3\u548c\u4f7f\u7528\u4f60\u7684\u4ee3\u7801\u3002<\/strong><\/p>\n<\/p>\n<p><p>\u4e00\u3001\u4ec0\u4e48\u662fPython\u6a21\u5757<\/p>\n<\/p>\n<p><p>Python\u6a21\u5757\u662f\u4e00\u4e2a\u5305\u542bPython\u5b9a\u4e49\u548c\u8bed\u53e5\u7684\u6587\u4ef6\u3002\u6a21\u5757\u53ef\u4ee5\u5b9a\u4e49\u51fd\u6570\u3001\u7c7b\u548c\u53d8\u91cf\uff0c\u4e5f\u53ef\u4ee5\u5305\u542b\u53ef\u6267\u884c\u4ee3\u7801\u3002\u6a21\u5757\u7684\u4e3b\u8981\u4f5c\u7528\u662f\u5c06\u4ee3\u7801\u7ec4\u7ec7\u6210\u53ef\u7ba1\u7406\u7684\u5757\uff0c\u65b9\u4fbf\u4ee3\u7801\u7684\u91cd\u7528\u548c\u7ef4\u62a4\u3002\u4e00\u4e2a\u6a21\u5757\u5c31\u662f\u4e00\u4e2aPython\u6587\u4ef6\uff0c\u6587\u4ef6\u540d\u662f\u6a21\u5757\u540d\u52a0\u4e0a.py\u540e\u7f00\u3002<\/p>\n<\/p>\n<p><p>\u6a21\u5757\u4e3a\u5f00\u53d1\u8005\u63d0\u4f9b\u4e86\u4ee3\u7801\u7684\u5206\u7ec4\u529f\u80fd\uff0c\u901a\u8fc7\u5c06\u76f8\u5173\u4ee3\u7801\u653e\u5728\u4e00\u8d77\uff0c\u6a21\u5757\u53ef\u4ee5\u5e2e\u52a9\u5f00\u53d1\u8005\u66f4\u597d\u5730\u7ec4\u7ec7\u4ee3\u7801\uff0c\u51cf\u5c11\u91cd\u590d\u3002Python\u7684\u6807\u51c6\u5e93\u672c\u8eab\u5c31\u662f\u4e00\u7ec4\u6a21\u5757\u7684\u96c6\u5408\uff0c\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u529f\u80fd\u4f9b\u5f00\u53d1\u8005\u4f7f\u7528\u3002<\/p>\n<\/p>\n<p><p>\u4e3a\u4e86\u4f7f\u7528\u6a21\u5757\u4e2d\u7684\u51fd\u6570\u548c\u53d8\u91cf\uff0c\u5f00\u53d1\u8005\u9700\u8981\u901a\u8fc7import\u8bed\u53e5\u5c06\u6a21\u5757\u5bfc\u5165\u5230\u5f53\u524d\u7684\u547d\u540d\u7a7a\u95f4\u4e2d\u3002\u4f8b\u5982\uff0c\u8981\u4f7f\u7528math\u6a21\u5757\u4e2d\u7684\u51fd\u6570\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u5bfc\u5165\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import math<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6216\u8005\uff0c\u53ea\u5bfc\u5165\u6a21\u5757\u4e2d\u7684\u67d0\u4e2a\u7279\u5b9a\u529f\u80fd\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from math import sqrt<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e8c\u3001docstring\u7684\u57fa\u672c\u7528\u6cd5<\/p>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0cdocstring\u662f\u7528\u4e8e\u4e3a\u6a21\u5757\u3001\u7c7b\u3001\u51fd\u6570\u548c\u65b9\u6cd5\u7f16\u5199\u6587\u6863\u7684\u5b57\u7b26\u4e32\u3002docstring\u53ef\u4ee5\u5e2e\u52a9\u5f00\u53d1\u8005\u7406\u89e3\u4ee3\u7801\u7684\u529f\u80fd\u548c\u7528\u6cd5\u3002docstring\u901a\u5e38\u4f4d\u4e8e\u6a21\u5757\u3001\u7c7b\u6216\u51fd\u6570\u5b9a\u4e49\u7684\u7b2c\u4e00\u884c\u5904\u3002<\/p>\n<\/p>\n<p><p>\u7f16\u5199docstring\u65f6\uff0c\u901a\u5e38\u4f7f\u7528\u4e09\u5bf9\u53cc\u5f15\u53f7\uff08&quot;&quot;&quot;\uff09\u5c06\u5b57\u7b26\u4e32\u5305\u56f4\uff0c\u4ee5\u652f\u6301\u591a\u884c\u6587\u672c\u3002\u4f8b\u5982\uff0c\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u51fd\u6570\u7684docstring\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def add(a, b):<\/p>\n<p>    &quot;&quot;&quot;<\/p>\n<p>    \u8ba1\u7b97\u4e24\u4e2a\u6570\u7684\u548c\u3002<\/p>\n<p>    \u53c2\u6570:<\/p>\n<p>    a -- \u7b2c\u4e00\u4e2a\u6570<\/p>\n<p>    b -- \u7b2c\u4e8c\u4e2a\u6570<\/p>\n<p>    \u8fd4\u56de\u503c:<\/p>\n<p>    \u4e24\u4e2a\u6570\u7684\u548c<\/p>\n<p>    &quot;&quot;&quot;<\/p>\n<p>    return a + b<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0cdocstring\u63cf\u8ff0\u4e86\u51fd\u6570\u7684\u7528\u9014\u3001\u53c2\u6570\u548c\u8fd4\u56de\u503c\u3002\u8fd9\u79cd\u683c\u5f0f\u4f7f\u5f97\u4ee3\u7801\u66f4\u52a0\u6613\u4e8e\u7406\u89e3\u548c\u4f7f\u7528\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u6a21\u5757\u7ea7docstring<\/p>\n<\/p>\n<p><p>\u6a21\u5757\u7ea7docstring\u4f4d\u4e8e\u6a21\u5757\u6587\u4ef6\u7684\u9876\u90e8\uff0c\u7528\u4e8e\u63cf\u8ff0\u6a21\u5757\u7684\u603b\u4f53\u529f\u80fd\u548c\u7528\u6cd5\u3002\u901a\u8fc7\u5728\u6a21\u5757\u5f00\u5934\u6dfb\u52a0\u4e00\u4e2adocstring\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u4e3a\u6a21\u5757\u63d0\u4f9b\u4e00\u4e2a\u6982\u89c8\uff0c\u5e2e\u52a9\u5176\u4ed6\u5f00\u53d1\u8005\u5feb\u901f\u4e86\u89e3\u6a21\u5757\u7684\u529f\u80fd\u548c\u4f7f\u7528\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><p>\u6a21\u5757\u7ea7docstring\u901a\u5e38\u5305\u542b\u4ee5\u4e0b\u4fe1\u606f\uff1a<\/p>\n<\/p>\n<ol>\n<li>\u6a21\u5757\u7684\u7528\u9014\u548c\u529f\u80fd\u6982\u8ff0\u3002<\/li>\n<li>\u6a21\u5757\u4e2d\u5305\u542b\u7684\u4e3b\u8981\u7c7b\u3001\u51fd\u6570\u6216\u53d8\u91cf\u3002<\/li>\n<li>\u4f7f\u7528\u6a21\u5757\u7684\u65b9\u6cd5\u548c\u793a\u4f8b\u3002<\/li>\n<li>\u4efb\u4f55\u7279\u6b8a\u7684\u6ce8\u610f\u4e8b\u9879\u6216\u9650\u5236\u3002<\/li>\n<\/ol>\n<p><p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u6a21\u5757\u7ea7docstring\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">&quot;&quot;&quot;<\/p>\n<p>math_utils\u6a21\u5757<\/p>\n<p>\u8be5\u6a21\u5757\u63d0\u4f9b\u4e86\u4e00\u4e9b\u6570\u5b66\u8ba1\u7b97\u7684\u5de5\u5177\u51fd\u6570\uff0c\u5305\u62ec\u52a0\u6cd5\u3001\u51cf\u6cd5\u3001\u4e58\u6cd5\u548c\u9664\u6cd5\u3002<\/p>\n<p>\u51fd\u6570:<\/p>\n<p>- add(a, b): \u8fd4\u56dea\u548cb\u7684\u548c\u3002<\/p>\n<p>- subtract(a, b): \u8fd4\u56dea\u51cf\u53bbb\u7684\u7ed3\u679c\u3002<\/p>\n<p>- multiply(a, b): \u8fd4\u56dea\u548cb\u7684\u4e58\u79ef\u3002<\/p>\n<p>- divide(a, b): \u8fd4\u56dea\u9664\u4ee5b\u7684\u7ed3\u679c\u3002<\/p>\n<p>\u6ce8\u610f: \u4f7f\u7528divide\u51fd\u6570\u65f6\uff0c\u8bf7\u786e\u4fdd\u53c2\u6570b\u4e0d\u4e3a0\u3002<\/p>\n<p>&quot;&quot;&quot;<\/p>\n<p>def add(a, b):<\/p>\n<p>    return a + b<\/p>\n<p>def subtract(a, b):<\/p>\n<p>    return a - b<\/p>\n<p>def multiply(a, b):<\/p>\n<p>    return a * b<\/p>\n<p>def divide(a, b):<\/p>\n<p>    if b == 0:<\/p>\n<p>        r<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>se ValueError(&quot;\u9664\u6570\u4e0d\u80fd\u4e3a0&quot;)<\/p>\n<p>    return a \/ b<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u56db\u3001\u7c7b\u548c\u65b9\u6cd5\u7684docstring<\/p>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u7c7b\u548c\u65b9\u6cd5\u4e5f\u53ef\u4ee5\u4f7f\u7528docstring\u6765\u8bb0\u5f55\u3002\u7c7b\u7684docstring\u5e94\u4f4d\u4e8e\u7c7b\u5b9a\u4e49\u7684\u7b2c\u4e00\u884c\uff0c\u7528\u4e8e\u63cf\u8ff0\u7c7b\u7684\u529f\u80fd\u3001\u5c5e\u6027\u548c\u4f7f\u7528\u65b9\u6cd5\u3002\u65b9\u6cd5\u7684docstring\u5219\u4f4d\u4e8e\u65b9\u6cd5\u5b9a\u4e49\u7684\u7b2c\u4e00\u884c\uff0c\u7528\u4e8e\u63cf\u8ff0\u65b9\u6cd5\u7684\u529f\u80fd\u3001\u53c2\u6570\u548c\u8fd4\u56de\u503c\u3002<\/p>\n<\/p>\n<p><p>\u4e0b\u9762\u662f\u4e00\u4e2a\u5e26\u6709\u7c7b\u548c\u65b9\u6cd5docstring\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">class Calculator:<\/p>\n<p>    &quot;&quot;&quot;<\/p>\n<p>    \u7b80\u5355\u7684\u8ba1\u7b97\u5668\u7c7b\uff0c\u7528\u4e8e\u6267\u884c\u57fa\u672c\u7684\u6570\u5b66\u8fd0\u7b97\u3002<\/p>\n<p>    \u5c5e\u6027:<\/p>\n<p>    result -- \u5b58\u50a8\u8ba1\u7b97\u7ed3\u679c<\/p>\n<p>    &quot;&quot;&quot;<\/p>\n<p>    def __init__(self):<\/p>\n<p>        &quot;&quot;&quot;\u521d\u59cb\u5316\u8ba1\u7b97\u5668\uff0c\u5c06\u7ed3\u679c\u8bbe\u7f6e\u4e3a0\u3002&quot;&quot;&quot;<\/p>\n<p>        self.result = 0<\/p>\n<p>    def add(self, a, b):<\/p>\n<p>        &quot;&quot;&quot;<\/p>\n<p>        \u8ba1\u7b97\u4e24\u4e2a\u6570\u7684\u548c\uff0c\u5e76\u66f4\u65b0\u7ed3\u679c\u3002<\/p>\n<p>        \u53c2\u6570:<\/p>\n<p>        a -- \u7b2c\u4e00\u4e2a\u52a0\u6570<\/p>\n<p>        b -- \u7b2c\u4e8c\u4e2a\u52a0\u6570<\/p>\n<p>        \u8fd4\u56de\u503c:<\/p>\n<p>        \u52a0\u6cd5\u7ed3\u679c<\/p>\n<p>        &quot;&quot;&quot;<\/p>\n<p>        self.result = a + b<\/p>\n<p>        return self.result<\/p>\n<p>    def subtract(self, a, b):<\/p>\n<p>        &quot;&quot;&quot;<\/p>\n<p>        \u8ba1\u7b97\u4e24\u4e2a\u6570\u7684\u5dee\uff0c\u5e76\u66f4\u65b0\u7ed3\u679c\u3002<\/p>\n<p>        \u53c2\u6570:<\/p>\n<p>        a -- \u88ab\u51cf\u6570<\/p>\n<p>        b -- \u51cf\u6570<\/p>\n<p>        \u8fd4\u56de\u503c:<\/p>\n<p>        \u51cf\u6cd5\u7ed3\u679c<\/p>\n<p>        &quot;&quot;&quot;<\/p>\n<p>        self.result = a - b<\/p>\n<p>        return self.result<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e94\u3001\u5982\u4f55\u8bbf\u95eedocstring<\/p>\n<\/p>\n<p><p>Python\u63d0\u4f9b\u4e86\u4e00\u4e2a\u5185\u7f6e\u51fd\u6570help()\uff0c\u53ef\u4ee5\u7528\u4e8e\u8bbf\u95ee\u6a21\u5757\u3001\u7c7b\u3001\u65b9\u6cd5\u548c\u51fd\u6570\u7684docstring\u3002\u4f7f\u7528help()\u51fd\u6570\u65f6\uff0cPython\u4f1a\u663e\u793a\u76f8\u5173\u5bf9\u8c61\u7684docstring\uff0c\u5e2e\u52a9\u5f00\u53d1\u8005\u4e86\u89e3\u5bf9\u8c61\u7684\u529f\u80fd\u548c\u7528\u6cd5\u3002<\/p>\n<\/p>\n<p><p>\u4f8b\u5982\uff0c\u8981\u67e5\u770badd\u51fd\u6570\u7684docstring\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">help(add)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6b64\u5916\uff0c\u53ef\u4ee5\u901a\u8fc7\u8bbf\u95ee\u5bf9\u8c61\u7684__doc__\u5c5e\u6027\u76f4\u63a5\u83b7\u53d6docstring\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">print(add.__doc__)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4e24\u79cd\u65b9\u6cd5\u90fd\u53ef\u4ee5\u5e2e\u52a9\u5f00\u53d1\u8005\u5feb\u901f\u8bbf\u95ee\u4ee3\u7801\u6587\u6863\uff0c\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u548c\u6613\u7528\u6027\u3002<\/p>\n<\/p>\n<p><p>\u516d\u3001\u7f16\u5199\u4f18\u79c0docstring\u7684\u6280\u5de7<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4fdd\u6301\u7b80\u6d01\u660e\u4e86<\/strong>\uff1adocstring\u5e94\u8be5\u6e05\u6670\u3001\u7b80\u6d01\u5730\u63cf\u8ff0\u4ee3\u7801\u7684\u529f\u80fd\uff0c\u907f\u514d\u4f7f\u7528\u5197\u957f\u590d\u6742\u7684\u8bed\u8a00\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528\u4e00\u81f4\u7684\u98ce\u683c<\/strong>\uff1a\u5728\u6574\u4e2a\u9879\u76ee\u4e2d\u4fdd\u6301\u4e00\u81f4\u7684docstring\u98ce\u683c\uff0c\u6709\u52a9\u4e8e\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u51c6\u786e\u63cf\u8ff0\u4ee3\u7801<\/strong>\uff1a\u786e\u4fdddocstring\u51c6\u786e\u63cf\u8ff0\u4ee3\u7801\u7684\u529f\u80fd\u3001\u53c2\u6570\u548c\u8fd4\u56de\u503c\uff0c\u907f\u514d\u8bef\u5bfc\u7528\u6237\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5305\u542b\u793a\u4f8b<\/strong>\uff1a\u5728docstring\u4e2d\u5305\u542b\u4f7f\u7528\u793a\u4f8b\uff0c\u53ef\u4ee5\u5e2e\u52a9\u7528\u6237\u66f4\u597d\u5730\u7406\u89e3\u4ee3\u7801\u7684\u7528\u6cd5\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5b9a\u671f\u66f4\u65b0<\/strong>\uff1a\u968f\u7740\u4ee3\u7801\u7684\u53d8\u5316\uff0c\u53ca\u65f6\u66f4\u65b0docstring\uff0c\u786e\u4fdd\u6587\u6863\u4e0e\u4ee3\u7801\u4fdd\u6301\u4e00\u81f4\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e03\u3001\u4f7f\u7528\u6587\u6863\u751f\u6210\u5de5\u5177<\/p>\n<\/p>\n<p><p>\u4e3a\u4e86\u63d0\u9ad8\u6587\u6863\u7684\u4e13\u4e1a\u6027\u548c\u4e00\u81f4\u6027\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u4f7f\u7528\u6587\u6863\u751f\u6210\u5de5\u5177\u81ea\u52a8\u751f\u6210\u9879\u76ee\u7684\u6587\u6863\u3002\u8fd9\u4e9b\u5de5\u5177\u53ef\u4ee5\u89e3\u6790\u4ee3\u7801\u4e2d\u7684docstring\uff0c\u5e76\u751f\u6210\u683c\u5f0f\u5316\u7684\u6587\u6863\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u4e9b\u5e38\u7528\u7684Python\u6587\u6863\u751f\u6210\u5de5\u5177\u5305\u62ec\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>Sphinx<\/strong>\uff1a\u4e00\u4e2a\u5f3a\u5927\u7684\u6587\u6863\u751f\u6210\u5de5\u5177\uff0c\u652f\u6301\u591a\u79cd\u8f93\u51fa\u683c\u5f0f\uff0c\u5982HTML\u3001PDF\u7b49\u3002Sphinx\u53ef\u4ee5\u89e3\u6790reStructuredText\u683c\u5f0f\u7684docstring\uff0c\u5e76\u751f\u6210\u7f8e\u89c2\u7684\u6587\u6863\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>pdoc<\/strong>\uff1a\u4e00\u4e2a\u7b80\u5355\u6613\u7528\u7684Python\u6587\u6863\u751f\u6210\u5de5\u5177\uff0c\u652f\u6301Markdown\u683c\u5f0f\u7684\u8f93\u51fa\u3002pdoc\u53ef\u4ee5\u81ea\u52a8\u751f\u6210\u6a21\u5757\u3001\u7c7b\u548c\u51fd\u6570\u7684\u6587\u6863\uff0c\u5e76\u652f\u6301\u591a\u79cd\u81ea\u5b9a\u4e49\u9009\u9879\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>PyDoc<\/strong>\uff1aPython\u5185\u7f6e\u7684\u6587\u6863\u5de5\u5177\uff0c\u53ef\u4ee5\u751f\u6210\u6a21\u5757\u3001\u7c7b\u548c\u51fd\u6570\u7684HTML\u6587\u6863\u3002PyDoc\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4\u884c\u8fd0\u884c\uff0c\u4e5f\u53ef\u4ee5\u4f5c\u4e3a\u4e00\u4e2a\u7b80\u5355\u7684HTTP\u670d\u52a1\u5668\u4f7f\u7528\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4f7f\u7528\u8fd9\u4e9b\u5de5\u5177\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u8f7b\u677e\u5730\u751f\u6210\u9879\u76ee\u7684\u5b8c\u6574\u6587\u6863\uff0c\u5e2e\u52a9\u5176\u4ed6\u5f00\u53d1\u8005\u7406\u89e3\u548c\u4f7f\u7528\u4ee3\u7801\u3002<\/p>\n<\/p>\n<p><p>\u516b\u3001\u603b\u7ed3<\/p>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u4f7f\u7528docstring\u4e3a\u6a21\u5757\u3001\u7c7b\u3001\u51fd\u6570\u548c\u65b9\u6cd5\u7f16\u5199\u6587\u6863\u662f\u4e00\u4e2a\u826f\u597d\u7684\u5b9e\u8df5\u3002docstring\u63d0\u4f9b\u4e86\u4e00\u79cd\u6807\u51c6\u5316\u7684\u65b9\u6cd5\u6765\u8bb0\u5f55\u4ee3\u7801\u7684\u529f\u80fd\u548c\u7528\u6cd5\uff0c\u6709\u52a9\u4e8e\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u548c\u53ef\u7ef4\u62a4\u6027\u3002\u901a\u8fc7\u9075\u5faa\u4e00\u5b9a\u7684\u683c\u5f0f\u548c\u98ce\u683c\u7f16\u5199docstring\uff0c\u5e76\u7ed3\u5408\u6587\u6863\u751f\u6210\u5de5\u5177\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u521b\u5efa\u51fa\u9ad8\u8d28\u91cf\u7684\u4ee3\u7801\u6587\u6863\uff0c\u5e2e\u52a9\u5176\u4ed6\u5f00\u53d1\u8005\u66f4\u597d\u5730\u7406\u89e3\u548c\u4f7f\u7528\u4ee3\u7801\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u4f7f\u7528 Python \u6a21\u5757\u751f\u6210\u6587\u6863\uff1f<\/strong><br \/>\u5728 Python \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 docstring \u6765\u4e3a\u6a21\u5757\u3001\u7c7b\u548c\u51fd\u6570\u751f\u6210\u6587\u6863\u3002\u901a\u8fc7\u5728\u6a21\u5757\u5f00\u5934\u6dfb\u52a0\u4e09\u91cd\u5f15\u53f7\u7684\u5b57\u7b26\u4e32\uff0c\u53ef\u4ee5\u8be6\u7ec6\u63cf\u8ff0\u6a21\u5757\u7684\u529f\u80fd\u3001\u4f7f\u7528\u65b9\u6cd5\u548c\u53c2\u6570\u8bf4\u660e\u3002\u6b64\u5916\uff0c\u4f7f\u7528\u5de5\u5177\u5982 Sphinx \u53ef\u4ee5\u5e2e\u52a9\u5c06\u8fd9\u4e9b\u6587\u6863\u8f6c\u6362\u6210 HTML \u6216 PDF \u683c\u5f0f\uff0c\u4f7f\u5f97\u6587\u6863\u66f4\u5177\u53ef\u8bfb\u6027\u548c\u53ef\u5206\u4eab\u6027\u3002<\/p>\n<p><strong>\u5982\u4f55\u67e5\u770b Python \u6a21\u5757\u7684\u6587\u6863\uff1f<\/strong><br \/>\u5728 Python \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u5185\u7f6e\u7684 help() \u51fd\u6570\u6765\u67e5\u770b\u6a21\u5757\u7684\u6587\u6863\u3002\u4f8b\u5982\uff0c\u8f93\u5165 <code>import module_name<\/code> \u540e\uff0c\u4f7f\u7528 <code>help(module_name)<\/code> \u53ef\u4ee5\u5feb\u901f\u67e5\u770b\u8be5\u6a21\u5757\u7684\u76f8\u5173\u6587\u6863\u4fe1\u606f\u3002\u6b64\u5916\uff0cPython \u7684\u4ea4\u4e92\u5f0f\u73af\u5883\u4e5f\u652f\u6301\u901a\u8fc7 <code>module_name.__doc__<\/code> \u76f4\u63a5\u83b7\u53d6\u6a21\u5757\u7684 docstring\u3002<\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528 Sphinx \u4e3a Python \u6a21\u5757\u751f\u6210\u6587\u6863\uff1f<\/strong><br \/>Sphinx \u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u6587\u6863\u751f\u6210\u5de5\u5177\uff0c\u4e13\u4e3a Python \u8bbe\u8ba1\u3002\u9996\u5148\uff0c\u9700\u5b89\u88c5 Sphinx\uff0c\u53ef\u4ee5\u901a\u8fc7 pip \u5b8c\u6210\u3002\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6587\u6863\u9879\u76ee\u540e\uff0c\u6309\u7167\u6307\u793a\u914d\u7f6e conf.py \u6587\u4ef6\uff0c\u6dfb\u52a0\u4f60\u7684\u6a21\u5757\u8def\u5f84\u3002\u5728\u4f60\u7684\u6587\u6863\u6e90\u6587\u4ef6\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 reStructuredText \u683c\u5f0f\u7f16\u5199\u6587\u6863\uff0c\u5e76\u901a\u8fc7\u547d\u4ee4 <code>make html<\/code> \u751f\u6210\u6700\u7ec8\u7684 HTML \u6587\u6863\uff0c\u65b9\u4fbf\u8fdb\u884c\u53d1\u5e03\u548c\u5206\u4eab\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\uff0c\u7f16\u5199\u6a21\u5757\u7684\u6587\u6863\u662f\u901a\u8fc7docstring\u6765\u5b9e\u73b0\u7684\u3001docstring\u662f\u4e00\u4e2a\u7528\u4e8e\u63cf\u8ff0\u6a21\u5757\u3001\u7c7b\u3001\u65b9 [&hellip;]","protected":false},"author":3,"featured_media":950657,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/950650"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=950650"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/950650\/revisions"}],"predecessor-version":[{"id":950658,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/950650\/revisions\/950658"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/950657"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=950650"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=950650"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=950650"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}