{"id":1135494,"date":"2025-01-08T21:26:06","date_gmt":"2025-01-08T13:26:06","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1135494.html"},"modified":"2025-01-08T21:26:09","modified_gmt":"2025-01-08T13:26:09","slug":"python%e4%b8%ad%e5%a6%82%e4%bd%95%e6%9f%a5%e4%b8%80%e4%b8%aa%e5%87%bd%e6%95%b0%e7%9a%84%e7%94%a8%e6%b3%95","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1135494.html","title":{"rendered":"python\u4e2d\u5982\u4f55\u67e5\u4e00\u4e2a\u51fd\u6570\u7684\u7528\u6cd5"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25104130\/4721f57f-bc5d-4fc5-8597-4ce03b545628.webp\" alt=\"python\u4e2d\u5982\u4f55\u67e5\u4e00\u4e2a\u51fd\u6570\u7684\u7528\u6cd5\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\u67e5\u627e\u4e00\u4e2a\u51fd\u6570\u7684\u7528\u6cd5\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff1a\u4f7f\u7528\u5185\u7f6e\u51fd\u6570help()\u3001\u67e5\u770b\u5b98\u65b9\u6587\u6863\u3001\u4f7f\u7528\u7b2c\u4e09\u65b9\u6587\u6863\u751f\u6210\u5de5\u5177\u5982Sphinx\u3001\u5229\u7528\u5728\u7ebf\u8d44\u6e90\u5982Stack Overflow\u7b49\u3002\u5176\u4e2d\uff0c\u6700\u76f4\u63a5\u548c\u5e38\u7528\u7684\u65b9\u6cd5\u662f\u4f7f\u7528\u5185\u7f6e\u51fd\u6570help()\u3002<\/strong> <\/p>\n<\/p>\n<p><p>\u4f7f\u7528\u5185\u7f6e\u51fd\u6570help()\u662f\u4e86\u89e3\u51fd\u6570\u7528\u6cd5\u7684\u6700\u76f4\u63a5\u65b9\u5f0f\u3002\u901a\u8fc7\u5728Python\u89e3\u91ca\u5668\u4e2d\u8f93\u5165help(\u51fd\u6570\u540d)\uff0c\u53ef\u4ee5\u67e5\u770b\u51fd\u6570\u7684\u6587\u6863\u5b57\u7b26\u4e32\uff08docstring\uff09\uff0c\u6587\u6863\u5b57\u7b26\u4e32\u901a\u5e38\u5305\u542b\u4e86\u51fd\u6570\u7684\u63cf\u8ff0\u3001\u53c2\u6570\u8bf4\u660e\u548c\u8fd4\u56de\u503c\u7b49\u4fe1\u606f\uff0c\u65b9\u4fbf\u5f00\u53d1\u8005\u5feb\u901f\u4e86\u89e3\u51fd\u6570\u7684\u4f7f\u7528\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<hr>\n<p><h3>\u4e00\u3001\u4f7f\u7528\u5185\u7f6e\u51fd\u6570help()<\/h3>\n<\/p>\n<p><p>Python\u63d0\u4f9b\u4e86\u4e00\u4e2a\u975e\u5e38\u6709\u7528\u7684\u5185\u7f6e\u51fd\u6570\u2014\u2014help()\uff0c\u5b83\u53ef\u4ee5\u76f4\u63a5\u5728\u89e3\u91ca\u5668\u4e2d\u4f7f\u7528\uff0c\u5e2e\u52a9\u4f60\u4e86\u89e3\u4efb\u4f55\u6a21\u5757\u3001\u7c7b\u3001\u65b9\u6cd5\u6216\u51fd\u6570\u7684\u8be6\u7ec6\u4fe1\u606f\u3002<\/p>\n<\/p>\n<p><h4>1.1 \u5982\u4f55\u4f7f\u7528help()\u51fd\u6570<\/h4>\n<\/p>\n<p><p>\u5728Python\u89e3\u91ca\u5668\u4e2d\uff0c\u4f60\u53ea\u9700\u8981\u7b80\u5355\u5730\u8c03\u7528help()\u51fd\u6570\uff0c\u5e76\u5c06\u4f60\u60f3\u8981\u4e86\u89e3\u7684\u51fd\u6570\u540d\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u7ed9\u5b83\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">help(len)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u4f1a\u8f93\u51fa\u5173\u4e8e<code>len()<\/code>\u51fd\u6570\u7684\u8be6\u7ec6\u4fe1\u606f\uff0c\u5305\u62ec\u5b83\u7684\u7528\u9014\u3001\u53c2\u6570\u548c\u8fd4\u56de\u503c\u7b49\u3002<\/p>\n<\/p>\n<p><h4>1.2 \u793a\u4f8b\uff1a\u67e5\u770blen()\u51fd\u6570\u7684\u7528\u6cd5<\/h4>\n<\/p>\n<p><p>\u5047\u8bbe\u4f60\u60f3\u77e5\u9053<code>len()<\/code>\u51fd\u6570\u7684\u7528\u6cd5\uff0c\u53ef\u4ee5\u8fd9\u6837\u505a\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">&gt;&gt;&gt; help(len)<\/p>\n<p>Help on built-in function len in module builtins:<\/p>\n<p>len(obj, \/)<\/p>\n<p>    Return the number of items in a cont<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>ner.<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4ece\u8f93\u51fa\u4e2d\u53ef\u4ee5\u770b\u5230\uff0c<code>len()<\/code>\u51fd\u6570\u63a5\u53d7\u4e00\u4e2a\u53c2\u6570<code>obj<\/code>\uff0c\u5e76\u8fd4\u56de\u8be5\u5bb9\u5668\u4e2d\u7684\u9879\u76ee\u6570\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u67e5\u770b\u5b98\u65b9\u6587\u6863<\/h3>\n<\/p>\n<p><p>Python\u7684\u5b98\u65b9\u6587\u6863\u662f\u4e86\u89e3\u5404\u79cd\u51fd\u6570\u548c\u6a21\u5757\u7684\u6700\u6743\u5a01\u7684\u8d44\u6e90\u3002\u5b98\u65b9\u6587\u6863\u8be6\u7ec6\u4ecb\u7ecd\u4e86\u6bcf\u4e2a\u51fd\u6570\u3001\u7c7b\u548c\u6a21\u5757\u7684\u7528\u6cd5\uff0c\u5e76\u63d0\u4f9b\u4e86\u793a\u4f8b\u4ee3\u7801\u3002<\/p>\n<\/p>\n<p><h4>2.1 \u5982\u4f55\u8bbf\u95ee\u5b98\u65b9\u6587\u6863<\/h4>\n<\/p>\n<p><p>\u4f60\u53ef\u4ee5\u901a\u8fc7\u8bbf\u95ee<a href=\"https:\/\/docs.python.org\/3\/\">Python\u5b98\u65b9\u6587\u6863\u7f51\u7ad9<\/a>\u6765\u67e5\u770b\u8be6\u7ec6\u7684\u6587\u6863\u3002\u5728\u641c\u7d22\u6846\u4e2d\u8f93\u5165\u4f60\u60f3\u8981\u67e5\u627e\u7684\u51fd\u6570\u540d\uff0c\u7136\u540e\u70b9\u51fb\u641c\u7d22\u6309\u94ae\u5373\u53ef\u3002<\/p>\n<\/p>\n<p><h4>2.2 \u793a\u4f8b\uff1a\u67e5\u770bsorted()\u51fd\u6570\u7684\u5b98\u65b9\u6587\u6863<\/h4>\n<\/p>\n<p><p>\u5047\u8bbe\u4f60\u60f3\u4e86\u89e3<code>sorted()<\/code>\u51fd\u6570\u7684\u7528\u6cd5\uff0c\u53ef\u4ee5\u5728\u5b98\u65b9\u6587\u6863\u4e2d\u8fdb\u884c\u641c\u7d22\u3002\u641c\u7d22\u7ed3\u679c\u4f1a\u663e\u793a\u5173\u4e8e<code>sorted()<\/code>\u51fd\u6570\u7684\u8be6\u7ec6\u4fe1\u606f\uff0c\u5305\u62ec\u53c2\u6570\u3001\u8fd4\u56de\u503c\u548c\u793a\u4f8b\u4ee3\u7801\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">sorted(iterable, *, key=None, reverse=False)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b98\u65b9\u6587\u6863\u4f1a\u89e3\u91ca<code>sorted()<\/code>\u51fd\u6570\u63a5\u53d7\u4e00\u4e2a\u53ef\u8fed\u4ee3\u5bf9\u8c61<code>iterable<\/code>\uff0c\u5e76\u8fd4\u56de\u4e00\u4e2a\u6392\u5e8f\u540e\u7684\u5217\u8868\u3002\u53ef\u4ee5\u9009\u62e9\u901a\u8fc7<code>key<\/code>\u53c2\u6570\u6307\u5b9a\u6392\u5e8f\u7684\u952e\u51fd\u6570\uff0c\u5e76\u901a\u8fc7<code>reverse<\/code>\u53c2\u6570\u6307\u5b9a\u662f\u5426\u8981\u53cd\u5411\u6392\u5e8f\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528\u7b2c\u4e09\u65b9\u6587\u6863\u751f\u6210\u5de5\u5177<\/h3>\n<\/p>\n<p><p>\u9664\u4e86\u5b98\u65b9\u6587\u6863\u548c\u5185\u7f6e\u7684help()\u51fd\u6570\uff0c\u7b2c\u4e09\u65b9\u6587\u6863\u751f\u6210\u5de5\u5177\u5982Sphinx\u4e5f\u975e\u5e38\u6709\u7528\u3002Sphinx\u53ef\u4ee5\u81ea\u52a8\u751f\u6210\u6587\u6863\uff0c\u5e76\u652f\u6301\u591a\u79cd\u8f93\u51fa\u683c\u5f0f\uff0c\u5982HTML\u3001PDF\u7b49\u3002<\/p>\n<\/p>\n<p><h4>3.1 \u5b89\u88c5Sphinx<\/h4>\n<\/p>\n<p><p>\u4f60\u53ef\u4ee5\u901a\u8fc7pip\u5b89\u88c5Sphinx\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install sphinx<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3.2 \u4f7f\u7528Sphinx\u751f\u6210\u6587\u6863<\/h4>\n<\/p>\n<p><p>\u4e00\u65e6\u5b89\u88c5\u4e86Sphinx\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u521d\u59cb\u5316\u4e00\u4e2a\u65b0\u7684\u6587\u6863\u9879\u76ee\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">sphinx-quickstart<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6309\u7167\u63d0\u793a\u914d\u7f6e\u9879\u76ee\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u751f\u6210\u6587\u6863\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">make html<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u751f\u6210\u7684HTML\u6587\u6863\u53ef\u4ee5\u5728\u6d4f\u89c8\u5668\u4e2d\u67e5\u770b\uff0c\u5305\u542b\u4e86\u9879\u76ee\u4e2d\u6240\u6709\u6a21\u5757\u548c\u51fd\u6570\u7684\u8be6\u7ec6\u4fe1\u606f\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u5229\u7528\u5728\u7ebf\u8d44\u6e90<\/h3>\n<\/p>\n<p><p>\u5728\u73b0\u4ee3\u7f16\u7a0b\u4e2d\uff0c\u5728\u7ebf\u8d44\u6e90\u5982Stack Overflow\u3001GitHub\u7b49\u4e5f\u662f\u975e\u5e38\u91cd\u8981\u7684\u5b66\u4e60\u548c\u67e5\u8be2\u5de5\u5177\u3002\u8fd9\u4e9b\u5e73\u53f0\u4e0a\u6709\u5927\u91cf\u7684\u5f00\u53d1\u8005\u5206\u4eab\u81ea\u5df1\u7684\u7ecf\u9a8c\u548c\u4ee3\u7801\u793a\u4f8b\uff0c\u5e2e\u52a9\u4f60\u5feb\u901f\u89e3\u51b3\u95ee\u9898\u3002<\/p>\n<\/p>\n<p><h4>4.1 \u4f7f\u7528Stack Overflow<\/h4>\n<\/p>\n<p><p>Stack Overflow\u662f\u4e00\u4e2a\u975e\u5e38\u53d7\u6b22\u8fce\u7684\u7f16\u7a0b\u95ee\u7b54\u793e\u533a\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u641c\u7d22\u76f8\u5173\u95ee\u9898\uff0c\u627e\u5230\u5176\u4ed6\u5f00\u53d1\u8005\u7684\u56de\u7b54\u548c\u4ee3\u7801\u793a\u4f8b\u3002<\/p>\n<\/p>\n<p><h4>4.2 \u4f7f\u7528GitHub<\/h4>\n<\/p>\n<p><p>GitHub\u662f\u4e00\u4e2a\u4ee3\u7801\u6258\u7ba1\u5e73\u53f0\uff0c\u8bb8\u591a\u5f00\u6e90\u9879\u76ee\u90fd\u5728GitHub\u4e0a\u53d1\u5e03\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u641c\u7d22\u9879\u76ee\u4ee3\u7801\uff0c\u4e86\u89e3\u51fd\u6570\u7684\u5177\u4f53\u5b9e\u73b0\u548c\u4f7f\u7528\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u7efc\u4e0a\u6240\u8ff0\uff0c<strong>\u67e5\u627ePython\u4e2d\u4e00\u4e2a\u51fd\u6570\u7684\u7528\u6cd5<\/strong>\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u5b9e\u73b0\uff0c\u5305\u62ec<strong>\u4f7f\u7528\u5185\u7f6e\u51fd\u6570help()\u3001\u67e5\u770b\u5b98\u65b9\u6587\u6863\u3001\u4f7f\u7528\u7b2c\u4e09\u65b9\u6587\u6863\u751f\u6210\u5de5\u5177\u5982Sphinx\u3001\u5229\u7528\u5728\u7ebf\u8d44\u6e90\u5982Stack Overflow<\/strong>\u7b49\u3002\u8fd9\u4e9b\u65b9\u6cd5\u5404\u6709\u4f18\u7f3a\u70b9\uff0c\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u60c5\u51b5\u9009\u62e9\u4f7f\u7528\u3002\u5e2e\u52a9\u4f60\u5feb\u901f\u3001\u51c6\u786e\u5730\u4e86\u89e3\u51fd\u6570\u7684\u7528\u6cd5\uff0c\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u4e0a\u8ff0\u65b9\u6cd5\uff0c\u4f60\u53ef\u4ee5\u5728Python\u5f00\u53d1\u4e2d\u66f4\u52a0\u5f97\u5fc3\u5e94\u624b\uff0c\u89e3\u51b3\u5404\u79cd\u7f16\u7a0b\u95ee\u9898\uff0c\u63d0\u9ad8\u4ee3\u7801\u8d28\u91cf\u548c\u5f00\u53d1\u6548\u7387\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u67e5\u627e\u51fd\u6570\u7684\u4f7f\u7528\u793a\u4f8b\uff1f<\/strong><br \/>Python\u7684\u5b98\u65b9\u6587\u6863\u662f\u67e5\u627e\u51fd\u6570\u7528\u6cd5\u7684\u9996\u9009\u8d44\u6e90\u3002\u60a8\u53ef\u4ee5\u8bbf\u95eePython\u7684\u5b98\u65b9\u7f51\u7ad9\uff0c\u641c\u7d22\u60a8\u611f\u5174\u8da3\u7684\u51fd\u6570\uff0c\u67e5\u770b\u5176\u8be6\u7ec6\u7684\u6587\u6863\u548c\u793a\u4f8b\u4ee3\u7801\u3002\u6b64\u5916\uff0c\u4f7f\u7528\u5185\u7f6e\u7684<code>help()<\/code>\u51fd\u6570\u4e5f\u80fd\u5feb\u901f\u83b7\u5f97\u6709\u5173\u51fd\u6570\u7684\u8bf4\u660e\u548c\u7528\u6cd5\u793a\u4f8b\u3002\u4f8b\u5982\uff0c\u8f93\u5165<code>help(len)<\/code>\u53ef\u4ee5\u770b\u5230<code>len()<\/code>\u51fd\u6570\u7684\u7528\u6cd5\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u5982\u4f55\u67e5\u770b\u4e00\u4e2a\u51fd\u6570\u7684\u53c2\u6570\u548c\u8fd4\u56de\u503c\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>help()<\/code>\u51fd\u6570\u6216\u8005\u67e5\u770b\u5b98\u65b9\u6587\u6863\u6765\u4e86\u89e3\u4e00\u4e2a\u51fd\u6570\u7684\u53c2\u6570\u548c\u8fd4\u56de\u503c\u3002\u4f7f\u7528<code>help(function_name)<\/code>\u5c06\u63d0\u4f9b\u8be5\u51fd\u6570\u7684\u63cf\u8ff0\uff0c\u5305\u62ec\u5176\u53c2\u6570\u3001\u9ed8\u8ba4\u503c\u548c\u8fd4\u56de\u7c7b\u578b\u3002\u6b64\u5916\uff0c\u4f7f\u7528IDE\u6216\u6587\u672c\u7f16\u8f91\u5668\u65f6\uff0c\u901a\u5e38\u4f1a\u63d0\u4f9b\u81ea\u52a8\u8865\u5168\u529f\u80fd\uff0c\u663e\u793a\u51fd\u6570\u7684\u53c2\u6570\u4fe1\u606f\uff0c\u5e2e\u52a9\u60a8\u66f4\u597d\u5730\u7406\u89e3\u5982\u4f55\u4f7f\u7528\u8be5\u51fd\u6570\u3002<\/p>\n<p><strong>\u662f\u5426\u6709\u5176\u4ed6\u5de5\u5177\u53ef\u4ee5\u5e2e\u52a9\u6211\u67e5\u627ePython\u51fd\u6570\u7684\u7528\u6cd5\uff1f<\/strong><br \/>\u9664\u4e86\u5b98\u65b9\u6587\u6863\u548c<code>help()<\/code>\u51fd\u6570\uff0c\u60a8\u8fd8\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e9b\u7b2c\u4e09\u65b9\u5de5\u5177\u548c\u5e93\uff0c\u4f8b\u5982Jupyter Notebook\u548cIPython\uff0c\u8fd9\u4e9b\u5de5\u5177\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u4ea4\u4e92\u5f0f\u73af\u5883\uff0c\u5141\u8bb8\u60a8\u76f4\u63a5\u8f93\u5165\u51fd\u6570\u5e76\u67e5\u770b\u5176\u6587\u6863\u3002\u6b64\u5916\uff0c\u4f7f\u7528\u50cfPyCharm\u6216VSCode\u8fd9\u6837\u7684\u4ee3\u7801\u7f16\u8f91\u5668\uff0c\u5b83\u4eec\u901a\u5e38\u5185\u7f6e\u4e86\u667a\u80fd\u63d0\u793a\u529f\u80fd\uff0c\u53ef\u4ee5\u5e2e\u52a9\u60a8\u5feb\u901f\u4e86\u89e3\u51fd\u6570\u7684\u7528\u6cd5\u548c\u53c2\u6570\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u67e5\u627e\u4e00\u4e2a\u51fd\u6570\u7684\u7528\u6cd5\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff1a\u4f7f\u7528\u5185\u7f6e\u51fd\u6570help()\u3001\u67e5\u770b\u5b98\u65b9\u6587\u6863\u3001\u4f7f\u7528\u7b2c\u4e09\u65b9\u6587\u6863\u751f\u6210\u5de5\u5177 [&hellip;]","protected":false},"author":3,"featured_media":1135497,"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\/1135494"}],"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=1135494"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1135494\/revisions"}],"predecessor-version":[{"id":1135501,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1135494\/revisions\/1135501"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1135497"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1135494"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1135494"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1135494"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}