{"id":1142866,"date":"2025-01-08T22:44:32","date_gmt":"2025-01-08T14:44:32","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1142866.html"},"modified":"2025-01-08T22:44:37","modified_gmt":"2025-01-08T14:44:37","slug":"%e8%ae%a1%e7%ae%97%e6%9c%ba%e4%ba%8c%e7%ba%a7python%e6%93%8d%e4%bd%9c%e9%a2%98%e5%a6%82%e4%bd%95%e6%93%8d%e4%bd%9c","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1142866.html","title":{"rendered":"\u8ba1\u7b97\u673a\u4e8c\u7ea7python\u64cd\u4f5c\u9898\u5982\u4f55\u64cd\u4f5c"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24180741\/c2373a1d-0a13-4455-af27-8bd872e317bc.webp\" alt=\"\u8ba1\u7b97\u673a\u4e8c\u7ea7python\u64cd\u4f5c\u9898\u5982\u4f55\u64cd\u4f5c\" \/><\/p>\n<p><p> <strong>\u8ba1\u7b97\u673a\u4e8c\u7ea7Python\u64cd\u4f5c\u9898\u5982\u4f55\u64cd\u4f5c<\/strong><\/p>\n<\/p>\n<p><p><strong>\u8ba1\u7b97\u673a\u4e8c\u7ea7Python\u64cd\u4f5c\u9898\u7684\u64cd\u4f5c\u6280\u5de7\u5305\u62ec\uff1a\u7406\u89e3\u9898\u76ee\u8981\u6c42\u3001\u719f\u6089\u5e38\u7528\u5e93\u3001\u638c\u63e1\u57fa\u7840\u8bed\u6cd5\u3001\u6ce8\u91cd\u4ee3\u7801\u89c4\u8303\u3001\u5229\u7528\u8c03\u8bd5\u5de5\u5177\u3002<\/strong> \u5176\u4e2d\uff0c\u7406\u89e3\u9898\u76ee\u8981\u6c42\u662f\u6700\u5173\u952e\u7684\u4e00\u6b65\uff0c\u56e0\u4e3a\u8fd9\u76f4\u63a5\u51b3\u5b9a\u4e86\u4f60\u80fd\u5426\u51c6\u786e\u89e3\u51b3\u95ee\u9898\u3002\u8be6\u7ec6\u7406\u89e3\u9898\u76ee\u8981\u6c42\u53ef\u4ee5\u5e2e\u52a9\u4f60\u786e\u5b9a\u9700\u8981\u5b9e\u73b0\u7684\u529f\u80fd\u3001\u8f93\u5165\u8f93\u51fa\u683c\u5f0f\u7b49\uff0c\u907f\u514d\u56e0\u8bef\u89e3\u9898\u610f\u800c\u4e22\u5206\u3002<\/p>\n<\/p>\n<h2><strong>\u4e00\u3001\u7406\u89e3\u9898\u76ee\u8981\u6c42<\/strong><\/h2>\n<p><p>\u5728\u8ba1\u7b97\u673a\u4e8c\u7ea7Python\u8003\u8bd5\u4e2d\uff0c\u9898\u76ee\u8981\u6c42\u901a\u5e38\u662f\u660e\u786e\u7684\uff0c\u4f46\u6709\u65f6\u4e5f\u4f1a\u6709\u4e00\u4e9b\u9690\u542b\u7684\u7ec6\u8282\u9700\u8981\u6ce8\u610f\u3002\u7406\u89e3\u9898\u76ee\u8981\u6c42\u7684\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><h3>1.1\u3001\u4ed4\u7ec6\u9605\u8bfb\u9898\u76ee<\/h3>\n<\/p>\n<p><p>\u5728\u62ff\u5230\u9898\u76ee\u540e\uff0c\u7b2c\u4e00\u6b65\u662f\u4ed4\u7ec6\u9605\u8bfb\u9898\u76ee\uff0c\u786e\u4fdd\u6bcf\u4e2a\u7ec6\u8282\u90fd\u7406\u89e3\u6e05\u695a\u3002\u4f8b\u5982\uff0c\u9898\u76ee\u53ef\u80fd\u8981\u6c42\u4f60\u5904\u7406\u67d0\u79cd\u7279\u5b9a\u7684\u6570\u636e\u683c\u5f0f\u3001\u5b9e\u73b0\u67d0\u4e9b\u7279\u5b9a\u7684\u529f\u80fd\u6216\u8005\u8f93\u51fa\u7279\u5b9a\u7684\u7ed3\u679c\u683c\u5f0f\u3002\u9605\u8bfb\u9898\u76ee\u65f6\uff0c\u5e94\u7279\u522b\u6ce8\u610f\u4ee5\u4e0b\u51e0\u70b9\uff1a<\/p>\n<\/p>\n<ul>\n<li><strong>\u8f93\u5165\u8f93\u51fa\u683c\u5f0f<\/strong>\uff1a\u9898\u76ee\u901a\u5e38\u4f1a\u660e\u786e\u89c4\u5b9a\u8f93\u5165\u548c\u8f93\u51fa\u7684\u683c\u5f0f\u3002\u4f8b\u5982\uff0c\u8f93\u5165\u662f\u4ece\u6587\u4ef6\u8bfb\u53d6\u8fd8\u662f\u4ece\u6807\u51c6\u8f93\u5165\u8bfb\u53d6\uff0c\u8f93\u51fa\u662f\u5199\u5165\u6587\u4ef6\u8fd8\u662f\u6253\u5370\u5230\u63a7\u5236\u53f0\u3002<\/li>\n<li><strong>\u529f\u80fd\u8981\u6c42<\/strong>\uff1a\u9898\u76ee\u53ef\u80fd\u8981\u6c42\u4f60\u5b9e\u73b0\u67d0\u4e9b\u7279\u5b9a\u7684\u529f\u80fd\uff0c\u5982\u6392\u5e8f\u3001\u67e5\u627e\u3001\u7edf\u8ba1\u7b49\u3002\u5728\u5b9e\u73b0\u8fd9\u4e9b\u529f\u80fd\u65f6\uff0c\u786e\u4fdd\u7406\u89e3\u6bcf\u4e2a\u529f\u80fd\u7684\u5177\u4f53\u8981\u6c42\u3002<\/li>\n<li><strong>\u8fb9\u754c\u6761\u4ef6<\/strong>\uff1a\u9898\u76ee\u53ef\u80fd\u4f1a\u6709\u4e00\u4e9b\u8fb9\u754c\u6761\u4ef6\uff0c\u5982\u8f93\u5165\u6570\u636e\u7684\u8303\u56f4\u3001\u7279\u6b8a\u60c5\u51b5\u4e0b\u7684\u5904\u7406\u7b49\u3002\u786e\u4fdd\u5728\u4ee3\u7801\u4e2d\u8003\u8651\u5230\u8fd9\u4e9b\u8fb9\u754c\u6761\u4ef6\u3002<\/li>\n<\/ul>\n<p><h3>1.2\u3001\u5212\u5206\u4efb\u52a1<\/h3>\n<\/p>\n<p><p>\u5728\u7406\u89e3\u9898\u76ee\u8981\u6c42\u540e\uff0c\u53ef\u4ee5\u5c06\u6574\u4e2a\u4efb\u52a1\u5212\u5206\u4e3a\u51e0\u4e2a\u5c0f\u4efb\u52a1\uff0c\u6bcf\u4e2a\u5c0f\u4efb\u52a1\u89e3\u51b3\u4e00\u4e2a\u5b50\u95ee\u9898\u3002\u8fd9\u6837\u53ef\u4ee5\u4f7f\u95ee\u9898\u66f4\u5bb9\u6613\u89e3\u51b3\uff0c\u4e5f\u66f4\u5bb9\u6613\u8c03\u8bd5\u3002\u4f8b\u5982\uff0c\u5982\u679c\u9898\u76ee\u8981\u6c42\u4f60\u5b9e\u73b0\u4e00\u4e2a\u6392\u5e8f\u7b97\u6cd5\uff0c\u4f60\u53ef\u4ee5\u5148\u5b9e\u73b0\u6570\u636e\u8bfb\u53d6\uff0c\u7136\u540e\u5b9e\u73b0\u6392\u5e8f\u7b97\u6cd5\uff0c\u6700\u540e\u5b9e\u73b0\u6570\u636e\u8f93\u51fa\u3002<\/p>\n<\/p>\n<p><h3>1.3\u3001\u5217\u51fa\u5173\u952e\u6b65\u9aa4<\/h3>\n<\/p>\n<p><p>\u5728\u5212\u5206\u4efb\u52a1\u540e\uff0c\u53ef\u4ee5\u5217\u51fa\u89e3\u51b3\u95ee\u9898\u7684\u5173\u952e\u6b65\u9aa4\u3002\u6bcf\u4e2a\u6b65\u9aa4\u53ef\u4ee5\u8fdb\u4e00\u6b65\u7ec6\u5316\u4e3a\u5177\u4f53\u7684\u64cd\u4f5c\u3002\u4f8b\u5982\uff0c\u5982\u679c\u9898\u76ee\u8981\u6c42\u4f60\u5b9e\u73b0\u4e00\u4e2a\u6570\u636e\u5904\u7406\u7a0b\u5e8f\uff0c\u53ef\u4ee5\u5217\u51fa\u4ee5\u4e0b\u5173\u952e\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u8bfb\u53d6\u6570\u636e<\/li>\n<li>\u5904\u7406\u6570\u636e<\/li>\n<li>\u8f93\u51fa\u7ed3\u679c<\/li>\n<\/ul>\n<p><p>\u6bcf\u4e2a\u6b65\u9aa4\u53ef\u4ee5\u8fdb\u4e00\u6b65\u7ec6\u5316\u4e3a\u5177\u4f53\u7684\u64cd\u4f5c\uff0c\u4f8b\u5982\u8bfb\u53d6\u6570\u636e\u53ef\u4ee5\u7ec6\u5316\u4e3a\u4ece\u6587\u4ef6\u4e2d\u8bfb\u53d6\u6570\u636e\u3001\u5c06\u6570\u636e\u5b58\u50a8\u5230\u5217\u8868\u4e2d\u7b49\u3002<\/p>\n<\/p>\n<h2><strong>\u4e8c\u3001\u719f\u6089\u5e38\u7528\u5e93<\/strong><\/h2>\n<p><p>Python\u6709\u5f88\u591a\u5f3a\u5927\u7684\u5e93\uff0c\u53ef\u4ee5\u5927\u5927\u7b80\u5316\u7f16\u7a0b\u4efb\u52a1\u3002\u5728\u8ba1\u7b97\u673a\u4e8c\u7ea7\u8003\u8bd5\u4e2d\uff0c\u719f\u6089\u5e38\u7528\u5e93\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u7528\u7684\u5e93\u53ca\u5176\u7528\u9014\uff1a<\/p>\n<\/p>\n<p><h3>2.1\u3001\u6807\u51c6\u5e93<\/h3>\n<\/p>\n<p><p>Python\u7684\u6807\u51c6\u5e93\u5305\u542b\u4e86\u5f88\u591a\u5e38\u7528\u7684\u6a21\u5757\uff0c\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<ul>\n<li><strong>os<\/strong>\uff1a\u7528\u4e8e\u8fdb\u884c\u64cd\u4f5c\u7cfb\u7edf\u76f8\u5173\u7684\u64cd\u4f5c\uff0c\u5982\u6587\u4ef6\u548c\u76ee\u5f55\u64cd\u4f5c\u3002<\/li>\n<li><strong>sys<\/strong>\uff1a\u7528\u4e8e\u8bbf\u95ee\u548c\u64cd\u4f5cPython\u89e3\u91ca\u5668\u7684\u8fd0\u884c\u73af\u5883\u3002<\/li>\n<li><strong>math<\/strong>\uff1a\u7528\u4e8e\u8fdb\u884c\u6570\u5b66\u8fd0\u7b97\uff0c\u5982\u4e09\u89d2\u51fd\u6570\u3001\u5bf9\u6570\u7b49\u3002<\/li>\n<li><strong>datetime<\/strong>\uff1a\u7528\u4e8e\u5904\u7406\u65e5\u671f\u548c\u65f6\u95f4\u3002<\/li>\n<\/ul>\n<p><h3>2.2\u3001\u7b2c\u4e09\u65b9\u5e93<\/h3>\n<\/p>\n<p><p>\u9664\u4e86\u6807\u51c6\u5e93\u5916\uff0cPython\u8fd8\u6709\u5f88\u591a\u5f3a\u5927\u7684\u7b2c\u4e09\u65b9\u5e93\uff0c\u53ef\u4ee5\u7528\u4e8e\u89e3\u51b3\u5404\u79cd\u95ee\u9898\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<ul>\n<li><strong>numpy<\/strong>\uff1a\u7528\u4e8e\u8fdb\u884c\u9ad8\u6548\u7684\u6570\u503c\u8ba1\u7b97\uff0c\u7279\u522b\u9002\u5408\u5904\u7406\u5927\u89c4\u6a21\u7684\u6570\u7ec4\u548c\u77e9\u9635\u3002<\/li>\n<li><strong>pandas<\/strong>\uff1a\u7528\u4e8e\u6570\u636e\u5206\u6790\u548c\u5904\u7406\uff0c\u63d0\u4f9b\u4e86\u9ad8\u6548\u7684\u6570\u636e\u64cd\u4f5c\u548c\u5206\u6790\u5de5\u5177\u3002<\/li>\n<li><strong>matplotlib<\/strong>\uff1a\u7528\u4e8e\u6570\u636e\u53ef\u89c6\u5316\uff0c\u53ef\u4ee5\u751f\u6210\u5404\u79cd\u56fe\u8868\uff0c\u5982\u6298\u7ebf\u56fe\u3001\u67f1\u72b6\u56fe\u7b49\u3002<\/li>\n<li><strong>requests<\/strong>\uff1a\u7528\u4e8e\u8fdb\u884cHTTP\u8bf7\u6c42\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u4ece\u7f51\u7edc\u4e0a\u83b7\u53d6\u6570\u636e\u3002<\/li>\n<\/ul>\n<p><p>\u719f\u6089\u8fd9\u4e9b\u5e93\u7684\u57fa\u672c\u7528\u6cd5\uff0c\u53ef\u4ee5\u5927\u5927\u7b80\u5316\u7f16\u7a0b\u4efb\u52a1\uff0c\u63d0\u9ad8\u7f16\u7a0b\u6548\u7387\u3002<\/p>\n<\/p>\n<h2><strong>\u4e09\u3001\u638c\u63e1\u57fa\u7840\u8bed\u6cd5<\/strong><\/h2>\n<p><p>\u638c\u63e1Python\u7684\u57fa\u7840\u8bed\u6cd5\u662f\u89e3\u51b3\u8ba1\u7b97\u673a\u4e8c\u7ea7Python\u64cd\u4f5c\u9898\u7684\u57fa\u7840\u3002\u5728\u8003\u8bd5\u4e2d\uff0c\u901a\u5e38\u9700\u8981\u7528\u5230\u4ee5\u4e0b\u57fa\u672c\u8bed\u6cd5\uff1a<\/p>\n<\/p>\n<p><h3>3.1\u3001\u53d8\u91cf\u548c\u6570\u636e\u7c7b\u578b<\/h3>\n<\/p>\n<p><p>Python\u652f\u6301\u591a\u79cd\u6570\u636e\u7c7b\u578b\uff0c\u5982\u6574\u6570\u3001\u6d6e\u70b9\u6570\u3001\u5b57\u7b26\u4e32\u3001\u5217\u8868\u3001\u5b57\u5178\u7b49\u3002\u5728\u7f16\u7a0b\u65f6\uff0c\u9700\u8981\u6b63\u786e\u4f7f\u7528\u548c\u64cd\u4f5c\u8fd9\u4e9b\u6570\u636e\u7c7b\u578b\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5b9a\u4e49\u53d8\u91cf<\/p>\n<p>a = 10<\/p>\n<p>b = 3.14<\/p>\n<p>c = &quot;Hello, World!&quot;<\/p>\n<p>d = [1, 2, 3, 4, 5]<\/p>\n<p>e = {&quot;name&quot;: &quot;Alice&quot;, &quot;age&quot;: 25}<\/p>\n<h2><strong>\u64cd\u4f5c\u53d8\u91cf<\/strong><\/h2>\n<p>print(a + b)<\/p>\n<p>print(c.upper())<\/p>\n<p>print(d[2])<\/p>\n<p>print(e[&quot;name&quot;])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>3.2\u3001\u63a7\u5236\u7ed3\u6784<\/h3>\n<\/p>\n<p><p>Python\u652f\u6301\u591a\u79cd\u63a7\u5236\u7ed3\u6784\uff0c\u5982\u6761\u4ef6\u8bed\u53e5\u3001\u5faa\u73af\u8bed\u53e5\u7b49\u3002\u5728\u7f16\u7a0b\u65f6\uff0c\u9700\u8981\u6b63\u786e\u4f7f\u7528\u8fd9\u4e9b\u63a7\u5236\u7ed3\u6784\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u6761\u4ef6\u8bed\u53e5<\/p>\n<p>if a &gt; 5:<\/p>\n<p>    print(&quot;a is greater than 5&quot;)<\/p>\n<p>else:<\/p>\n<p>    print(&quot;a is not greater than 5&quot;)<\/p>\n<h2><strong>\u5faa\u73af\u8bed\u53e5<\/strong><\/h2>\n<p>for i in range(5):<\/p>\n<p>    print(i)<\/p>\n<p>while a &gt; 0:<\/p>\n<p>    print(a)<\/p>\n<p>    a -= 1<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>3.3\u3001\u51fd\u6570\u548c\u6a21\u5757<\/h3>\n<\/p>\n<p><p>Python\u652f\u6301\u5b9a\u4e49\u548c\u8c03\u7528\u51fd\u6570\uff0c\u53ef\u4ee5\u5c06\u4ee3\u7801\u7ec4\u7ec7\u6210\u6a21\u5757\u5316\u7684\u7ed3\u6784\u3002\u5728\u7f16\u7a0b\u65f6\uff0c\u9700\u8981\u6b63\u786e\u5b9a\u4e49\u548c\u8c03\u7528\u51fd\u6570\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5b9a\u4e49\u51fd\u6570<\/p>\n<p>def add(x, y):<\/p>\n<p>    return x + y<\/p>\n<h2><strong>\u8c03\u7528\u51fd\u6570<\/strong><\/h2>\n<p>result = add(5, 3)<\/p>\n<p>print(result)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<h2><strong>\u56db\u3001\u6ce8\u91cd\u4ee3\u7801\u89c4\u8303<\/strong><\/h2>\n<p><p>\u5728\u8ba1\u7b97\u673a\u4e8c\u7ea7Python\u8003\u8bd5\u4e2d\uff0c\u4ee3\u7801\u89c4\u8303\u4e5f\u662f\u4e00\u4e2a\u91cd\u8981\u7684\u8bc4\u5224\u6807\u51c6\u3002\u826f\u597d\u7684\u4ee3\u7801\u89c4\u8303\u53ef\u4ee5\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u548c\u53ef\u7ef4\u62a4\u6027\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u7684\u4ee3\u7801\u89c4\u8303\uff1a<\/p>\n<\/p>\n<p><h3>4.1\u3001\u547d\u540d\u89c4\u8303<\/h3>\n<\/p>\n<p><p>\u53d8\u91cf\u540d\u3001\u51fd\u6570\u540d\u7b49\u5e94\u4f7f\u7528\u6709\u610f\u4e49\u7684\u540d\u5b57\uff0c\u5e76\u9075\u5faa\u4e00\u5b9a\u7684\u547d\u540d\u89c4\u8303\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u53d8\u91cf\u540d\u548c\u51fd\u6570\u540d\u5e94\u4f7f\u7528\u5c0f\u5199\u5b57\u6bcd\u548c\u4e0b\u5212\u7ebf\u5206\u9694\uff0c\u5982<code>my_variable<\/code>\u3001<code>my_function<\/code>\u3002<\/li>\n<li>\u7c7b\u540d\u5e94\u4f7f\u7528\u5927\u5199\u5b57\u6bcd\u5f00\u5934\u7684\u5355\u8bcd\uff0c\u5982<code>MyClass<\/code>\u3002<\/li>\n<\/ul>\n<p><h3>4.2\u3001\u4ee3\u7801\u7f29\u8fdb<\/h3>\n<\/p>\n<p><p>Python\u4f7f\u7528\u7f29\u8fdb\u8868\u793a\u4ee3\u7801\u5757\uff0c\u6b63\u786e\u7684\u7f29\u8fdb\u53ef\u4ee5\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">if a &gt; 5:<\/p>\n<p>    print(&quot;a is greater than 5&quot;)<\/p>\n<p>    if b &lt; 10:<\/p>\n<p>        print(&quot;b is less than 10&quot;)<\/p>\n<p>else:<\/p>\n<p>    print(&quot;a is not greater than 5&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>4.3\u3001\u6ce8\u91ca<\/h3>\n<\/p>\n<p><p>\u5728\u4ee3\u7801\u4e2d\u6dfb\u52a0\u9002\u5f53\u7684\u6ce8\u91ca\uff0c\u53ef\u4ee5\u5e2e\u52a9\u7406\u89e3\u4ee3\u7801\u7684\u903b\u8f91\u548c\u529f\u80fd\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u8ba1\u7b97\u4e24\u4e2a\u6570\u7684\u548c<\/p>\n<p>def add(x, y):<\/p>\n<p>    return x + y<\/p>\n<h2><strong>\u6253\u5370\u7ed3\u679c<\/strong><\/h2>\n<p>result = add(5, 3)<\/p>\n<p>print(result)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<h2><strong>\u4e94\u3001\u5229\u7528\u8c03\u8bd5\u5de5\u5177<\/strong><\/h2>\n<p><p>\u5728\u7f16\u7a0b\u8fc7\u7a0b\u4e2d\uff0c\u8c03\u8bd5\u662f\u975e\u5e38\u91cd\u8981\u7684\u4e00\u73af\u3002\u5229\u7528\u8c03\u8bd5\u5de5\u5177\u53ef\u4ee5\u5e2e\u52a9\u53d1\u73b0\u548c\u89e3\u51b3\u4ee3\u7801\u4e2d\u7684\u95ee\u9898\u3002\u5728\u8ba1\u7b97\u673a\u4e8c\u7ea7Python\u8003\u8bd5\u4e2d\uff0c\u5e38\u7528\u7684\u8c03\u8bd5\u5de5\u5177\u548c\u65b9\u6cd5\u5305\u62ec\uff1a<\/p>\n<\/p>\n<p><h3>5.1\u3001print\u8bed\u53e5<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528<code>print<\/code>\u8bed\u53e5\u53ef\u4ee5\u5728\u4ee3\u7801\u6267\u884c\u8fc7\u7a0b\u4e2d\u8f93\u51fa\u53d8\u91cf\u7684\u503c\uff0c\u5e2e\u52a9\u8c03\u8bd5\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def add(x, y):<\/p>\n<p>    print(&quot;x:&quot;, x)<\/p>\n<p>    print(&quot;y:&quot;, y)<\/p>\n<p>    return x + y<\/p>\n<p>result = add(5, 3)<\/p>\n<p>print(result)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>5.2\u3001\u65ad\u70b9\u8c03\u8bd5<\/h3>\n<\/p>\n<p><p>\u5728IDE\u4e2d\u8bbe\u7f6e\u65ad\u70b9\uff0c\u53ef\u4ee5\u5728\u4ee3\u7801\u6267\u884c\u5230\u65ad\u70b9\u5904\u6682\u505c\uff0c\u67e5\u770b\u53d8\u91cf\u7684\u503c\u548c\u4ee3\u7801\u7684\u6267\u884c\u8fc7\u7a0b\u3002\u4f8b\u5982\uff0c\u5728PyCharm\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u70b9\u51fb\u884c\u53f7\u5de6\u4fa7\u7684\u7a7a\u767d\u5904\u8bbe\u7f6e\u65ad\u70b9\uff0c\u7136\u540e\u8fd0\u884c\u8c03\u8bd5\u3002<\/p>\n<\/p>\n<p><h3>5.3\u3001\u8c03\u8bd5\u5de5\u5177<\/h3>\n<\/p>\n<p><p>Python\u6709\u4e00\u4e9b\u5185\u7f6e\u7684\u8c03\u8bd5\u5de5\u5177\uff0c\u5982<code>pdb<\/code>\u6a21\u5757\uff0c\u53ef\u4ee5\u5728\u4ee3\u7801\u4e2d\u63d2\u5165\u65ad\u70b9\uff0c\u8fdb\u884c\u5355\u6b65\u8c03\u8bd5\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pdb<\/p>\n<p>def add(x, y):<\/p>\n<p>    pdb.set_trace()<\/p>\n<p>    return x + y<\/p>\n<p>result = add(5, 3)<\/p>\n<p>print(result)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd0\u884c\u4ee3\u7801\u65f6\uff0c\u7a0b\u5e8f\u4f1a\u5728<code>pdb.set_trace()<\/code>\u5904\u6682\u505c\uff0c\u53ef\u4ee5\u8f93\u5165\u8c03\u8bd5\u547d\u4ee4\uff0c\u5982<code>n<\/code>\uff08\u4e0b\u4e00\u6b65\uff09\u3001<code>c<\/code>\uff08\u7ee7\u7eed\u8fd0\u884c\uff09\u7b49\u3002<\/p>\n<\/p>\n<h2><strong>\u516d\u3001\u5e38\u89c1\u9898\u578b\u89e3\u6790<\/strong><\/h2>\n<p><p>\u5728\u8ba1\u7b97\u673a\u4e8c\u7ea7Python\u8003\u8bd5\u4e2d\uff0c\u5e38\u89c1\u7684\u9898\u578b\u5305\u62ec\uff1a\u6570\u636e\u5904\u7406\u3001\u6392\u5e8f\u4e0e\u67e5\u627e\u3001\u5b57\u7b26\u4e32\u64cd\u4f5c\u3001\u6587\u4ef6\u64cd\u4f5c\u3001\u56fe\u5f62\u7ed8\u5236\u7b49\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u9898\u578b\u7684\u89e3\u6790\uff1a<\/p>\n<\/p>\n<p><h3>6.1\u3001\u6570\u636e\u5904\u7406<\/h3>\n<\/p>\n<p><p>\u6570\u636e\u5904\u7406\u9898\u578b\u901a\u5e38\u8981\u6c42\u4f60\u8bfb\u53d6\u6570\u636e\u3001\u5904\u7406\u6570\u636e\u5e76\u8f93\u51fa\u7ed3\u679c\u3002\u4f8b\u5982\uff0c\u8ba1\u7b97\u5e73\u5747\u503c\u3001\u6c42\u548c\u3001\u7edf\u8ba1\u9891\u7387\u7b49\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u8ba1\u7b97\u5e73\u5747\u503c\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def calculate_average(numbers):<\/p>\n<p>    total = sum(numbers)<\/p>\n<p>    count = len(numbers)<\/p>\n<p>    average = total \/ count<\/p>\n<p>    return average<\/p>\n<p>numbers = [1, 2, 3, 4, 5]<\/p>\n<p>average = calculate_average(numbers)<\/p>\n<p>print(&quot;Average:&quot;, average)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>6.2\u3001\u6392\u5e8f\u4e0e\u67e5\u627e<\/h3>\n<\/p>\n<p><p>\u6392\u5e8f\u4e0e\u67e5\u627e\u9898\u578b\u901a\u5e38\u8981\u6c42\u4f60\u5b9e\u73b0\u67d0\u79cd\u6392\u5e8f\u7b97\u6cd5\u6216\u67e5\u627e\u7b97\u6cd5\u3002\u4f8b\u5982\uff0c\u5192\u6ce1\u6392\u5e8f\u3001\u4e8c\u5206\u67e5\u627e\u7b49\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u5192\u6ce1\u6392\u5e8f\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def bubble_sort(arr):<\/p>\n<p>    n = len(arr)<\/p>\n<p>    for i in range(n):<\/p>\n<p>        for j in range(0, n-i-1):<\/p>\n<p>            if arr[j] &gt; arr[j+1]:<\/p>\n<p>                arr[j], arr[j+1] = arr[j+1], arr[j]<\/p>\n<p>arr = [64, 34, 25, 12, 22, 11, 90]<\/p>\n<p>bubble_sort(arr)<\/p>\n<p>print(&quot;Sorted array:&quot;, arr)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>6.3\u3001\u5b57\u7b26\u4e32\u64cd\u4f5c<\/h3>\n<\/p>\n<p><p>\u5b57\u7b26\u4e32\u64cd\u4f5c\u9898\u578b\u901a\u5e38\u8981\u6c42\u4f60\u8fdb\u884c\u5b57\u7b26\u4e32\u7684\u5904\u7406\uff0c\u5982\u5b57\u7b26\u4e32\u7684\u62c6\u5206\u3001\u62fc\u63a5\u3001\u66ff\u6362\u7b49\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\u62c6\u5206\u548c\u62fc\u63a5\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def split_and_join(string):<\/p>\n<p>    words = string.split()<\/p>\n<p>    result = &quot;-&quot;.join(words)<\/p>\n<p>    return result<\/p>\n<p>string = &quot;Hello World from Python&quot;<\/p>\n<p>result = split_and_join(string)<\/p>\n<p>print(&quot;Result:&quot;, result)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>6.4\u3001\u6587\u4ef6\u64cd\u4f5c<\/h3>\n<\/p>\n<p><p>\u6587\u4ef6\u64cd\u4f5c\u9898\u578b\u901a\u5e38\u8981\u6c42\u4f60\u8fdb\u884c\u6587\u4ef6\u7684\u8bfb\u53d6\u548c\u5199\u5165\u3002\u4f8b\u5982\uff0c\u4ece\u6587\u4ef6\u4e2d\u8bfb\u53d6\u6570\u636e\u3001\u5c06\u6570\u636e\u5199\u5165\u6587\u4ef6\u7b49\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u8bfb\u53d6\u6587\u4ef6\u5185\u5bb9\u5e76\u7edf\u8ba1\u5355\u8bcd\u9891\u7387\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def count_word_frequency(filename):<\/p>\n<p>    with open(filename, &#39;r&#39;) as file:<\/p>\n<p>        text = file.read()<\/p>\n<p>    words = text.split()<\/p>\n<p>    frequency = {}<\/p>\n<p>    for word in words:<\/p>\n<p>        if word in frequency:<\/p>\n<p>            frequency[word] += 1<\/p>\n<p>        else:<\/p>\n<p>            frequency[word] = 1<\/p>\n<p>    return frequency<\/p>\n<p>filename = &quot;example.txt&quot;<\/p>\n<p>frequency = count_word_frequency(filename)<\/p>\n<p>print(&quot;Word frequency:&quot;, frequency)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>6.5\u3001\u56fe\u5f62\u7ed8\u5236<\/h3>\n<\/p>\n<p><p>\u56fe\u5f62\u7ed8\u5236\u9898\u578b\u901a\u5e38\u8981\u6c42\u4f60\u4f7f\u7528Python\u7684\u56fe\u5f62\u5e93\uff0c\u5982matplotlib\uff0c\u7ed8\u5236\u5404\u79cd\u56fe\u8868\u3002\u4f8b\u5982\uff0c\u7ed8\u5236\u6298\u7ebf\u56fe\u3001\u67f1\u72b6\u56fe\u7b49\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7ed8\u5236\u6298\u7ebf\u56fe\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>def plot_line_chart(x, y):<\/p>\n<p>    plt.plot(x, y)<\/p>\n<p>    plt.xlabel(&#39;X-axis&#39;)<\/p>\n<p>    plt.ylabel(&#39;Y-axis&#39;)<\/p>\n<p>    plt.title(&#39;Line Chart&#39;)<\/p>\n<p>    plt.show()<\/p>\n<p>x = [1, 2, 3, 4, 5]<\/p>\n<p>y = [2, 3, 5, 7, 11]<\/p>\n<p>plot_line_chart(x, y)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<h2><strong>\u4e03\u3001\u5b9e\u8df5\u4e0e\u7ec3\u4e60<\/strong><\/h2>\n<p><p>\u5728\u638c\u63e1\u4e86\u4e0a\u8ff0\u6280\u5de7\u548c\u77e5\u8bc6\u540e\uff0c\u5b9e\u8df5\u548c\u7ec3\u4e60\u662f\u63d0\u9ad8\u7f16\u7a0b\u80fd\u529b\u7684\u5173\u952e\u3002\u901a\u8fc7\u4e0d\u65ad\u7684\u7ec3\u4e60\uff0c\u53ef\u4ee5\u719f\u6089\u5404\u79cd\u9898\u578b\uff0c\u63d0\u9ad8\u89e3\u51b3\u95ee\u9898\u7684\u6548\u7387\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5b9e\u8df5\u548c\u7ec3\u4e60\u7684\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<p><h3>7.1\u3001\u5728\u7ebf\u7f16\u7a0b\u5e73\u53f0<\/h3>\n<\/p>\n<p><p>\u5728\u7ebf\u7f16\u7a0b\u5e73\u53f0\u63d0\u4f9b\u4e86\u5927\u91cf\u7684\u7f16\u7a0b\u9898\u76ee\u548c\u5373\u65f6\u53cd\u9988\uff0c\u53ef\u4ee5\u5e2e\u52a9\u4f60\u7ec3\u4e60\u548c\u63d0\u9ad8\u7f16\u7a0b\u80fd\u529b\u3002\u4f8b\u5982\uff0cLeetCode\u3001CodeSignal\u3001HackerRank\u7b49\u5e73\u53f0\u90fd\u6709\u4e30\u5bcc\u7684\u9898\u5e93\u548c\u7ade\u8d5b\u3002<\/p>\n<\/p>\n<p><h3>7.2\u3001\u6a21\u62df\u8003\u8bd5<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7\u6a21\u62df\u8003\u8bd5\uff0c\u53ef\u4ee5\u719f\u6089\u8003\u8bd5\u7684\u6d41\u7a0b\u548c\u9898\u578b\uff0c\u63d0\u9ad8\u5e94\u8bd5\u80fd\u529b\u3002\u53ef\u4ee5\u627e\u4e00\u4e9b\u8ba1\u7b97\u673a\u4e8c\u7ea7Python\u8003\u8bd5\u7684\u6a21\u62df\u9898\uff0c\u8fdb\u884c\u5b9a\u65f6\u7ec3\u4e60\uff0c\u6a21\u62df\u771f\u5b9e\u8003\u8bd5\u7684\u73af\u5883\u3002<\/p>\n<\/p>\n<p><h3>7.3\u3001\u9879\u76ee\u5b9e\u8df5<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7\u5b9e\u9645\u9879\u76ee\u7684\u5f00\u53d1\uff0c\u53ef\u4ee5\u5c06\u5b66\u5230\u7684\u77e5\u8bc6\u5e94\u7528\u5230\u5b9e\u9645\u95ee\u9898\u4e2d\uff0c\u63d0\u9ad8\u7f16\u7a0b\u80fd\u529b\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u5f00\u53d1\u4e00\u4e2a\u7b80\u5355\u7684\u7f51\u9875\u722c\u866b\u3001\u6570\u636e\u5206\u6790\u5de5\u5177\u3001\u5c0f\u6e38\u620f\u7b49\u9879\u76ee\u3002<\/p>\n<\/p>\n<h2><strong>\u516b\u3001\u603b\u7ed3<\/strong><\/h2>\n<p><p>\u8ba1\u7b97\u673a\u4e8c\u7ea7Python\u64cd\u4f5c\u9898\u7684\u64cd\u4f5c\u6280\u5de7\u5305\u62ec\uff1a\u7406\u89e3\u9898\u76ee\u8981\u6c42\u3001\u719f\u6089\u5e38\u7528\u5e93\u3001\u638c\u63e1\u57fa\u7840\u8bed\u6cd5\u3001\u6ce8\u91cd\u4ee3\u7801\u89c4\u8303\u3001\u5229\u7528\u8c03\u8bd5\u5de5\u5177\u3002\u901a\u8fc7\u4e0d\u65ad\u7684\u5b9e\u8df5\u548c\u7ec3\u4e60\uff0c\u53ef\u4ee5\u719f\u6089\u5404\u79cd\u9898\u578b\uff0c\u63d0\u9ad8\u89e3\u51b3\u95ee\u9898\u7684\u6548\u7387\u3002\u5728\u8003\u8bd5\u4e2d\uff0c\u4fdd\u6301\u51b7\u9759\u3001\u4ed4\u7ec6\u9605\u8bfb\u9898\u76ee\u3001\u5408\u7406\u5206\u914d\u65f6\u95f4\uff0c\u662f\u53d6\u5f97\u597d\u6210\u7ee9\u7684\u5173\u952e\u3002\u5e0c\u671b\u901a\u8fc7\u672c\u6587\u7684\u4ecb\u7ecd\uff0c\u80fd\u591f\u5e2e\u52a9\u4f60\u66f4\u597d\u5730\u51c6\u5907\u8ba1\u7b97\u673a\u4e8c\u7ea7Python\u8003\u8bd5\uff0c\u53d6\u5f97\u4f18\u5f02\u7684\u6210\u7ee9\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u51c6\u5907\u8ba1\u7b97\u673a\u4e8c\u7ea7Python\u64cd\u4f5c\u9898\u7684\u8003\u8bd5\uff1f<\/strong><br \/>\u51c6\u5907\u8ba1\u7b97\u673a\u4e8c\u7ea7Python\u64cd\u4f5c\u9898\u7684\u5173\u952e\u5728\u4e8e\u7406\u89e3\u8003\u8bd5\u5185\u5bb9\u548c\u5f62\u5f0f\u3002\u5efa\u8bae\u9996\u5148\u719f\u6089Python\u7684\u57fa\u672c\u8bed\u6cd5\u3001\u6570\u636e\u7ed3\u6784\u3001\u51fd\u6570\u548c\u6a21\u5757\uff0c\u505a\u4e00\u4e9b\u7ec3\u4e60\u9898\u6765\u5de9\u56fa\u7406\u8bba\u77e5\u8bc6\u3002\u53ef\u4ee5\u4f7f\u7528\u5728\u7ebf\u7f16\u7a0b\u5e73\u53f0\u8fdb\u884c\u7ec3\u4e60\uff0c\u6a21\u62df\u8003\u8bd5\u73af\u5883\uff0c\u63d0\u5347\u5b9e\u9645\u64cd\u4f5c\u80fd\u529b\u3002\u6b64\u5916\uff0c\u67e5\u9605\u5386\u5e74\u7684\u8003\u8bd5\u771f\u9898\u548c\u590d\u4e60\u8d44\u6599\uff0c\u5c06\u6709\u52a9\u4e8e\u638c\u63e1\u51fa\u9898\u7684\u91cd\u70b9\u548c\u96be\u70b9\u3002<\/p>\n<p><strong>\u5728\u8ba1\u7b97\u673a\u4e8c\u7ea7Python\u8003\u8bd5\u4e2d\uff0c\u5e38\u89c1\u7684\u64cd\u4f5c\u9898\u578b\u6709\u54ea\u4e9b\uff1f<\/strong><br \/>\u8ba1\u7b97\u673a\u4e8c\u7ea7Python\u8003\u8bd5\u901a\u5e38\u5305\u62ec\u7f16\u5199\u51fd\u6570\u3001\u5b9e\u73b0\u7b97\u6cd5\u3001\u6570\u636e\u5904\u7406\u548c\u7b80\u5355\u7684\u56fe\u5f62\u754c\u9762\u8bbe\u8ba1\u7b49\u9898\u578b\u3002\u5e38\u89c1\u7684\u9898\u76ee\u53ef\u80fd\u8981\u6c42\u8003\u751f\u7f16\u5199\u4ee3\u7801\u89e3\u51b3\u7279\u5b9a\u95ee\u9898\uff0c\u6216\u8005\u5bf9\u7ed9\u5b9a\u7684\u4ee3\u7801\u8fdb\u884c\u8c03\u8bd5\u548c\u4f18\u5316\u3002\u4e86\u89e3\u8fd9\u4e9b\u9898\u578b\u6709\u52a9\u4e8e\u8003\u751f\u6709\u9488\u5bf9\u6027\u5730\u8fdb\u884c\u590d\u4e60\u548c\u7ec3\u4e60\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728\u8003\u8bd5\u4e2d\u6709\u6548\u7ba1\u7406\u65f6\u95f4\u4ee5\u5b8c\u6210\u6240\u6709Python\u64cd\u4f5c\u9898\uff1f<\/strong><br \/>\u65f6\u95f4\u7ba1\u7406\u5728\u8003\u8bd5\u4e2d\u81f3\u5173\u91cd\u8981\u3002\u53ef\u4ee5\u91c7\u7528\u4ee5\u4e0b\u7b56\u7565\uff1a\u9996\u5148\uff0c\u5feb\u901f\u6d4f\u89c8\u6240\u6709\u9898\u76ee\uff0c\u786e\u5b9a\u6bcf\u9053\u9898\u7684\u96be\u6613\u7a0b\u5ea6\u548c\u6240\u9700\u65f6\u95f4\u3002\u5bf9\u4e8e\u8f83\u7b80\u5355\u7684\u9898\u76ee\uff0c\u53ef\u4ee5\u4f18\u5148\u89e3\u51b3\uff0c\u4ee5\u83b7\u5f97\u4fe1\u5fc3\u548c\u65f6\u95f4\u7684\u7f13\u51b2\u3002\u590d\u6742\u7684\u9898\u76ee\u53ef\u4ee5\u5148\u8bb0\u5f55\u601d\u8def\uff0c\u518d\u8fdb\u884c\u8be6\u7ec6\u7f16\u5199\u3002\u5b9a\u671f\u68c0\u67e5\u5269\u4f59\u65f6\u95f4\uff0c\u786e\u4fdd\u6bcf\u9053\u9898\u90fd\u6709\u8db3\u591f\u7684\u65f6\u95f4\u8fdb\u884c\u89e3\u7b54\u548c\u68c0\u67e5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u8ba1\u7b97\u673a\u4e8c\u7ea7Python\u64cd\u4f5c\u9898\u5982\u4f55\u64cd\u4f5c \u8ba1\u7b97\u673a\u4e8c\u7ea7Python\u64cd\u4f5c\u9898\u7684\u64cd\u4f5c\u6280\u5de7\u5305\u62ec\uff1a\u7406\u89e3\u9898\u76ee\u8981\u6c42\u3001\u719f\u6089\u5e38\u7528\u5e93\u3001\u638c [&hellip;]","protected":false},"author":3,"featured_media":1142877,"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\/1142866"}],"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=1142866"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1142866\/revisions"}],"predecessor-version":[{"id":1142882,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1142866\/revisions\/1142882"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1142877"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1142866"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1142866"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1142866"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}