{"id":292519,"date":"2024-05-20T14:21:04","date_gmt":"2024-05-20T06:21:04","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/292519.html"},"modified":"2024-05-20T14:21:22","modified_gmt":"2024-05-20T06:21:22","slug":"idle-%e9%87%8c%e9%9d%a2%e5%a6%82%e4%bd%95%e5%86%99%e5%87%bd%e6%95%b0","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/292519.html","title":{"rendered":"idle \u91cc\u9762\u5982\u4f55\u5199\u51fd\u6570"},"content":{"rendered":"<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/27135217\/137caf1c-f27c-4dbc-a779-adf31fc55800.webp\" alt=\"idle \u91cc\u9762\u5982\u4f55\u5199\u51fd\u6570\" \/><\/p>\n<p><p>\u5728IDLE\u4e2d\u7f16\u5199\u51fd\u6570\u662f\u4e00\u9879\u57fa\u7840\u4e14\u91cd\u8981\u7684\u7f16\u7a0b\u6280\u80fd\uff0c\u5b83\u5bf9\u4e8e\u63d0\u9ad8Python\u4ee3\u7801\u7684\u6a21\u5757\u5316\u548c\u590d\u7528\u6027\u81f3\u5173\u91cd\u8981\u3002<strong>\u5728IDLE\u4e2d\u7f16\u5199\u51fd\u6570\u4e3b\u8981\u9075\u5faa\u5b9a\u4e49\u51fd\u6570\u540d\u3001\u8bbe\u5b9a\u53c2\u6570\u3001\u7f16\u5199\u51fd\u6570\u4f53\u3001\u8fd4\u56de\u7ed3\u679c<\/strong>\u7b49\u6b65\u9aa4\uff0c\u5176\u4e2d<strong>\u7f16\u5199\u51fd\u6570\u4f53<\/strong>\u662f\u51fd\u6570\u5b9a\u4e49\u4e2d\u6700\u5173\u952e\u7684\u90e8\u5206\uff0c\u56e0\u4e3a\u5b83\u786e\u5b9a\u4e86\u51fd\u6570\u7684\u5177\u4f53\u6267\u884c\u8fc7\u7a0b\u548c\u884c\u4e3a\u3002\u7f16\u5199\u51fd\u6570\u4f53\u65f6\uff0c\u4f60\u9700\u8981\u5173\u6ce8\u5b9e\u73b0\u529f\u80fd\u7684\u903b\u8f91\uff0c\u786e\u4fdd\u4ee3\u7801\u65e2\u7b80\u6d01\u53c8\u6613\u4e8e\u7406\u89e3\u3002\u6b64\u5916\uff0c\u4f7f\u7528\u9002\u5f53\u7684\u6ce8\u91ca\u6765\u89e3\u91ca\u4ee3\u7801\u7684\u610f\u56fe\uff0c\u662f\u826f\u597d\u7f16\u7801\u4e60\u60ef\u7684\u4f53\u73b0\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u521b\u5efa\u65b0\u7684Python\u6587\u4ef6<\/h3>\n<\/p>\n<p><p>\u5728IDLE\u73af\u5883\u4e2d\uff0c\u9996\u5148\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Python\u6587\u4ef6\u3002\u901a\u8fc7\u5728\u6587\u4ef6\u83dc\u5355\u9009\u62e9\u201c\u65b0\u5efa\u6587\u4ef6\u201d\uff0c\u5728\u6253\u5f00\u7684\u7f16\u8f91\u5668\u7a97\u53e3\u4e2d\u64b0\u5199\u4f60\u7684\u4ee3\u7801\u3002\u8fd9\u4e2a\u6b65\u9aa4\u662f\u7f16\u5199Python\u51fd\u6570\u7684\u8d77\u70b9\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u5b9a\u4e49\u51fd\u6570\u7ed3\u6784<\/h3>\n<\/p>\n<p><p>\u5b9a\u4e49\u51fd\u6570\u7684\u57fa\u672c\u7ed3\u6784\u6d89\u53ca\u5230\u5173\u952e\u5b57<code>def<\/code>\u540e\u8ddf\u51fd\u6570\u540d\u548c\u62ec\u53f7\u5185\u7684\u53c2\u6570\u5217\u8868\uff0c\u4ee5\u53ca\u4e00\u4e2a\u5192\u53f7\u3002\u5728\u5b9a\u4e49\u4e4b\u540e\uff0c\u4f60\u5c06\u7f16\u5199\u51fd\u6570\u4f53\uff0c\u5b83\u63cf\u8ff0\u4e86\u51fd\u6570\u5e94\u5f53\u6267\u884c\u7684\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><h4>\u51fd\u6570\u58f0\u660e<\/h4>\n<\/p>\n<p><p>\u51fd\u6570\u4ee5<code>def<\/code>\u5173\u952e\u5b57\u5f00\u59cb\uff0c\u8868\u793a\u4f60\u5c06\u5b9a\u4e49\u4e00\u4e2a\u65b0\u7684\u51fd\u6570\u3002\u4e4b\u540e\u662f\u51fd\u6570\u540d\uff0c\u5b83\u5e94\u8be5\u7b80\u77ed\u800c\u63cf\u8ff0\u6027\u5f3a\uff0c\u4f7f\u5f97\u5176\u4ed6\u7a0b\u5e8f\u5458\u80fd\u591f\u901a\u8fc7\u540d\u79f0\u7406\u89e3\u51fd\u6570\u7684\u76ee\u7684\u3002<\/p>\n<\/p>\n<p><h4>\u53c2\u6570\u5217\u8868<\/h4>\n<\/p>\n<p><p>\u51fd\u6570\u53ef\u4ee5\u6709\u96f6\u4e2a\u6216\u591a\u4e2a\u53c2\u6570\uff0c\u8fd9\u4e9b\u53c2\u6570\u4f4d\u4e8e\u51fd\u6570\u540d\u4e4b\u540e\u7684\u62ec\u53f7\u4e2d\u3002\u5728\u5b9a\u4e49\u51fd\u6570\u65f6\u7ed9\u51fa\u53c2\u6570\uff0c\u4f7f\u5f97\u51fd\u6570\u80fd\u591f\u5904\u7406\u4e0d\u540c\u7684\u8f93\u5165\u503c\uff0c\u63d0\u9ad8\u51fd\u6570\u7684\u901a\u7528\u6027\u548c\u7075\u6d3b\u6027\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u7f16\u5199\u51fd\u6570\u4f53<\/h3>\n<\/p>\n<p><p>\u7f16\u5199\u51fd\u6570\u4f53\u662f\u5b9a\u4e49\u51fd\u6570\u7684\u6838\u5fc3\u8fc7\u7a0b\u3002\u5728\u51fd\u6570\u4f53\u4e2d\uff0c\u4f60\u5c06\u6839\u636e\u51fd\u6570\u7684\u76ee\u7684\u5b9e\u73b0\u5177\u4f53\u7684\u903b\u8f91\u3002<\/p>\n<\/p>\n<p><h4>\u5b9e\u73b0\u51fd\u6570\u903b\u8f91<\/h4>\n<\/p>\n<p><p>\u57fa\u4e8e\u51fd\u6570\u7684\u9884\u671f\u529f\u80fd\u7f16\u5199\u4ee3\u7801\u3002\u8fd9\u53ef\u80fd\u5305\u62ec\u5904\u7406\u8f93\u5165\u6570\u636e\u3001\u6267\u884c\u8ba1\u7b97\u6216\u5176\u4ed6\u64cd\u4f5c\u7b49\u3002\u4fdd\u8bc1\u4ee3\u7801\u6e05\u6670\u548c\u9ad8\u6548\u662f\u81f3\u5173\u91cd\u8981\u7684\u3002<\/p>\n<\/p>\n<p><h4>\u4f7f\u7528\u9002\u5f53\u7684\u7f29\u8fdb<\/h4>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u7f29\u8fdb\u662f\u533a\u5206\u4ee3\u7801\u5757\u7684\u91cd\u8981\u65b9\u5f0f\u3002\u786e\u4fdd\u51fd\u6570\u4f53\u5185\u7684\u6240\u6709\u8bed\u53e5\u90fd\u6b63\u786e\u7f29\u8fdb\uff0c\u4ee5\u4fbfPython\u89e3\u91ca\u5668\u80fd\u591f\u6b63\u786e\u7406\u89e3\u4f60\u7684\u4ee3\u7801\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u8fd4\u56de\u7ed3\u679c<\/h3>\n<\/p>\n<p><p>\u5728\u51fd\u6570\u7684\u672b\u5c3e\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528<code>return<\/code>\u5173\u952e\u5b57\u6765\u8fd4\u56de\u51fd\u6570\u7684\u7ed3\u679c\u3002\u8fd4\u56de\u503c\u662f\u51fd\u6570\u5b8c\u6210\u5176\u4efb\u52a1\u540e\u63d0\u4f9b\u7ed9\u8c03\u7528\u8005\u7684\u6570\u636e\u3002<\/p>\n<\/p>\n<p><h4>\u4f7f\u7528return\u8bed\u53e5<\/h4>\n<\/p>\n<p><p><code>return<\/code>\u8bed\u53e5\u786e\u5b9a\u4e86\u51fd\u6570\u7684\u8f93\u51fa\u3002\u4f60\u53ef\u4ee5\u8fd4\u56de\u4efb\u4f55\u7c7b\u578b\u7684\u6570\u636e\uff0c\u5305\u62ec\u4f46\u4e0d\u9650\u4e8e\u6570\u5b57\u3001\u5b57\u7b26\u4e32\u3001\u5217\u8868\u6216\u5176\u4ed6\u6570\u636e\u7ed3\u6784\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u8c03\u7528\u51fd\u6570<\/h3>\n<\/p>\n<p><p>\u5b9a\u4e49\u51fd\u6570\u540e\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u7b80\u5355\u5730\u5199\u4e0a\u51fd\u6570\u540d\u548c\u62ec\u53f7\u4e2d\u7684\u5b9e\u53c2\u6765\u8c03\u7528\u5b83\u3002\u8c03\u7528\u51fd\u6570\u65f6\uff0c\u786e\u4fdd\u63d0\u4f9b\u6b63\u786e\u6570\u91cf\u548c\u7c7b\u578b\u7684\u5b9e\u53c2\uff0c\u4e0e\u51fd\u6570\u5b9a\u4e49\u65f6\u7684\u5f62\u53c2\u76f8\u5339\u914d\u3002<\/p>\n<\/p>\n<p><h4>\u5b9e\u9645\u8c03\u7528\u793a\u4f8b<\/h4>\n<\/p>\n<p><p>\u5c55\u793a\u5982\u4f55\u5728\u4ee3\u7801\u4e2d\u8c03\u7528\u4e0a\u8ff0\u5b9a\u4e49\u7684\u51fd\u6570\uff0c\u5e76\u5904\u7406\u8fd4\u56de\u503c\u3002<\/p>\n<\/p>\n<p><h4>\u53c2\u6570\u4f20\u9012<\/h4>\n<\/p>\n<p><p>\u8ba8\u8bba\u5728\u51fd\u6570\u8c03\u7528\u4e2d\u4f20\u9012\u53c2\u6570\u7684\u4e0d\u540c\u65b9\u5f0f\uff0c\u5305\u62ec\u4f4d\u7f6e\u53c2\u6570\u548c\u5173\u952e\u5b57\u53c2\u6570\uff0c\u4ee5\u53ca\u5982\u4f55\u4f7f\u7528\u9ed8\u8ba4\u53c2\u6570\u503c\u6765\u63d0\u9ad8\u51fd\u6570\u7684\u7075\u6d3b\u6027\u3002<\/p>\n<\/p>\n<p><p>\u7f16\u5199\u51fd\u6570\u662f\u638c\u63e1\u4efb\u4f55\u7f16\u7a0b\u8bed\u8a00\u7684\u57fa\u7840\uff0c\u5c24\u5176\u662f\u5728Python\u8fd9\u7c7b\u9ad8\u7ea7\u8bed\u8a00\u4e2d\u3002\u901a\u8fc7\u5728IDLE\u4e2d\u5b9e\u8df5\u7f16\u5199\u3001\u8c03\u8bd5\u548c\u8c03\u7528\u51fd\u6570\uff0c\u4f60\u80fd\u591f\u63d0\u9ad8\u7f16\u7a0b\u6280\u80fd\uff0c\u66f4\u597d\u5730\u7406\u89e3\u7a0b\u5e8f\u7684\u7ed3\u6784\u4e0e\u8bbe\u8ba1\u3002\u6b64\u5916\uff0c\u638c\u63e1\u51fd\u6570\u7f16\u5199\u5bf9\u4e8e\u65e5\u540e\u5b66\u4e60\u66f4\u9ad8\u7ea7\u7684\u7f16\u7a0b\u6982\u5ff5\uff0c\u5982\u7c7b\u548c\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\uff08OOP\uff09\uff0c\u6253\u4e0b\u575a\u5b9e\u7684\u57fa\u7840\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p><strong>1.<\/strong> <strong>\u5982\u4f55\u5728idle\u4e2d\u7f16\u5199\u5e76\u8fd0\u884c\u51fd\u6570\uff1f<\/strong><\/p>\n<p>\u5728IDLE\u4e2d\u7f16\u5199\u51fd\u6570\u975e\u5e38\u7b80\u5355\u3002\u9996\u5148\uff0c\u6253\u5f00IDLE\u5e76\u521b\u5efa\u4e00\u4e2a\u65b0\u6587\u4ef6\u3002\u7136\u540e\uff0c\u4f7f\u7528&quot;def&quot;\u5173\u952e\u5b57\u5b9a\u4e49\u51fd\u6570\u5e76\u7ed9\u5b83\u4e00\u4e2a\u5408\u9002\u7684\u540d\u79f0\u3002\u63a5\u4e0b\u6765\uff0c\u5728\u5192\u53f7\u540e\u9762\u6dfb\u52a0\u51fd\u6570\u7684\u4e3b\u4f53\u4ee3\u7801\u5757\uff0c\u5e76\u4f7f\u7528\u7f29\u8fdb\u6765\u8868\u793a\u5b83\u5c5e\u4e8e\u51fd\u6570\u3002\u6700\u540e\uff0c\u5728\u51fd\u6570\u7684\u672b\u5c3e\u4f7f\u7528&quot;return&quot;\u5173\u952e\u5b57\u8fd4\u56de\u9700\u8981\u7684\u7ed3\u679c\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u4e0b\u9762\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u51fd\u6570\u793a\u4f8b\uff0c\u7528\u4e8e\u8ba1\u7b97\u4e24\u4e2a\u6570\u5b57\u7684\u548c\uff1a<\/p>\n<pre><code class=\"language-python\">def add_numbers(a, b):\n    result = a + b\n    return result\n<\/code><\/pre>\n<p>\u60a8\u53ef\u4ee5\u5728IDLE\u4e2d\u6309\u4e0b\u201cF5\u201d\u952e\u6216\u901a\u8fc7\u201cRun\u201d\u83dc\u5355\u4e2d\u7684\u201cRun Module\u201d\u9009\u9879\u6765\u8fd0\u884c\u8fd9\u4e2a\u51fd\u6570\u3002<\/p>\n<p><strong>2.<\/strong> <strong>\u5982\u4f55\u5728idle\u91cc\u9762\u8c03\u7528\u81ea\u5df1\u7f16\u5199\u7684\u51fd\u6570\uff1f<\/strong><\/p>\n<p>\u8981\u5728IDLE\u4e2d\u8c03\u7528\u81ea\u5df1\u7f16\u5199\u7684\u51fd\u6570\uff0c\u60a8\u9700\u8981\u5728\u60a8\u7684\u4ee3\u7801\u4e2d\u6dfb\u52a0\u51fd\u6570\u8c03\u7528\u7684\u8bed\u53e5\u3002\u4e3a\u4e86\u8c03\u7528\u51fd\u6570\uff0c\u60a8\u9700\u8981\u4f7f\u7528\u51fd\u6570\u7684\u540d\u79f0\u540e\u8ddf\u62ec\u53f7\uff0c\u5e76\u5c06\u6240\u6709\u9700\u8981\u7684\u53c2\u6570\u4f20\u9012\u7ed9\u51fd\u6570\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u5047\u8bbe\u60a8\u5df2\u7ecf\u5b9a\u4e49\u4e86\u4e00\u4e2a\u540d\u4e3aadd_numbers\u7684\u51fd\u6570\uff0c\u5e76\u4e14\u5e0c\u671b\u8c03\u7528\u5b83\u6765\u8ba1\u7b975\u548c3\u7684\u548c\u3002<\/p>\n<p>\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8bed\u53e5\u5728IDLE\u4e2d\u8c03\u7528\u8fd9\u4e2a\u51fd\u6570\uff1a<\/p>\n<pre><code class=\"language-python\">result = add_numbers(5, 3)\nprint(result)\n<\/code><\/pre>\n<p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u901a\u8fc7\u4f20\u90125\u548c3\u4f5c\u4e3a\u53c2\u6570\u6765\u8c03\u7528add_numbers\u51fd\u6570\uff0c\u5e76\u5c06\u7ed3\u679c\u5b58\u50a8\u5728\u53d8\u91cfresult\u4e2d\u3002\u7136\u540e\uff0c\u6211\u4eec\u4f7f\u7528print\u8bed\u53e5\u6765\u663e\u793a\u7ed3\u679c\u3002<\/p>\n<p><strong>3.<\/strong> <strong>\u5982\u4f55\u5c06\u51fd\u6570\u4fdd\u5b58\u4e3aPython\u6587\u4ef6\uff0c\u5e76\u5728idle\u4e2d\u8c03\u7528\uff1f<\/strong><\/p>\n<p>\u60a8\u53ef\u4ee5\u5c06\u51fd\u6570\u4fdd\u5b58\u4e3aPython\u6587\u4ef6\uff0c\u5e76\u5728IDLE\u4e2d\u8c03\u7528\u5b83\u3002\u9996\u5148\uff0c\u5c06\u51fd\u6570\u590d\u5236\u5230\u4e00\u4e2a\u65b0\u7684\u6587\u672c\u6587\u4ef6\u4e2d\uff0c\u5e76\u5c06\u6587\u4ef6\u4fdd\u5b58\u4e3a\u4ee5.py\u4e3a\u6269\u5c55\u540d\u7684\u6587\u4ef6\uff08\u4f8b\u5982\uff0cmy_functions.py\uff09\u3002<\/p>\n<p>\u7136\u540e\uff0c\u5728IDLE\u4e2d\u6253\u5f00\u4e00\u4e2a\u65b0\u6587\u4ef6\uff08\u6216\u73b0\u6709\u6587\u4ef6\uff09\uff0c\u5e76\u4f7f\u7528&quot;import&quot;\u8bed\u53e5\u5bfc\u5165\u60a8\u7684\u51fd\u6570\u3002\u4f8b\u5982\uff0c\u5982\u679c\u60a8\u4fdd\u5b58\u7684\u6587\u4ef6\u540d\u4e3amy_functions.py\uff0c\u5e76\u4e14\u5176\u4e2d\u5305\u542b\u4e00\u4e2a\u540d\u4e3aadd_numbers\u7684\u51fd\u6570\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8bed\u53e5\u5728IDLE\u4e2d\u5bfc\u5165\u5b83\uff1a<\/p>\n<pre><code class=\"language-python\">from my_functions import add_numbers\n<\/code><\/pre>\n<p>\u73b0\u5728\uff0c\u60a8\u53ef\u4ee5\u5728IDLE\u4e2d\u8c03\u7528add_numbers\u51fd\u6570\uff0c\u5c31\u50cf\u5b83\u662f\u5728\u540c\u4e00\u4e2a\u6587\u4ef6\u4e2d\u5b9a\u4e49\u7684\u4e00\u6837\uff1a<\/p>\n<pre><code class=\"language-python\">result = add_numbers(5, 3)\nprint(result)\n<\/code><\/pre>\n<p>\u8fd9\u5c06\u4f7f\u60a8\u80fd\u591f\u5728IDLE\u4e2d\u4f7f\u7528\u6765\u81ea\u5176\u4ed6Python\u6587\u4ef6\u7684\u51fd\u6570\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728IDLE\u4e2d\u7f16\u5199\u51fd\u6570\u662f\u4e00\u9879\u57fa\u7840\u4e14\u91cd\u8981\u7684\u7f16\u7a0b\u6280\u80fd\uff0c\u5b83\u5bf9\u4e8e\u63d0\u9ad8Python\u4ee3\u7801\u7684\u6a21\u5757\u5316\u548c\u590d\u7528\u6027\u81f3\u5173\u91cd\u8981\u3002\u5728IDLE [&hellip;]","protected":false},"author":3,"featured_media":292550,"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\/292519"}],"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=292519"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/292519\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/292550"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=292519"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=292519"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=292519"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}