{"id":48111,"date":"2024-12-02T16:48:21","date_gmt":"2024-12-02T08:48:21","guid":{"rendered":"https:\/\/fwq.ai\/blog\/48111\/"},"modified":"2024-12-02T16:48:21","modified_gmt":"2024-12-02T08:48:21","slug":"%e5%a6%82%e4%bd%95%e8%b0%83%e8%af%95%e5%92%8c%e6%8e%92%e6%9f%a5%e8%87%aa%e5%ae%9a%e4%b9%89%e5%87%bd%e6%95%b0%e4%b8%ad%e7%9a%84%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/48111\/","title":{"rendered":"\u5982\u4f55\u8c03\u8bd5\u548c\u6392\u67e5\u81ea\u5b9a\u4e49\u51fd\u6570\u4e2d\u7684\u95ee\u9898"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u5982\u4f55\u8c03\u8bd5\u548c\u6392\u67e5\u81ea\u5b9a\u4e49\u51fd\u6570\u4e2d\u7684\u95ee\u9898<\/h1>\n<p>IT\u884c\u4e1a\u76f8\u5bf9\u4e8e\u4e00\u822c\u4f20\u7edf\u884c\u4e1a\uff0c\u53d1\u5c55\u66f4\u65b0\u901f\u5ea6\u66f4\u5feb\uff0c\u4e00\u65e6\u505c\u6b62\u4e86\u5b66\u4e60\uff0c\u5f88\u5feb\u5c31\u4f1a\u88ab\u884c\u4e1a\u6240\u6dd8\u6c70\u3002\u6240\u4ee5\u6211\u4eec\u9700\u8981\u8e0f\u8e0f\u5b9e\u5b9e\u7684\u4e0d\u65ad\u5b66\u4e60\uff0c\u7cbe\u8fdb\u81ea\u5df1\u7684\u6280\u672f\uff0c\u5c24\u5176\u662f\u521d\u5b66\u8005\u3002\u4eca\u5929\u7c73\u4e91\u7ed9\u5927\u5bb6\u6574\u7406\u4e86\u300a\u5982\u4f55\u8c03\u8bd5\u548c\u6392\u67e5\u81ea\u5b9a\u4e49\u51fd\u6570\u4e2d\u7684\u95ee\u9898\u300b\uff0c\u804a\u804a\uff0c\u6211\u4eec\u4e00\u8d77\u6765\u770b\u770b\u5427\uff01<\/p>\n<p>\u5982\u4f55\u8c03\u8bd5\u548c\u6392\u67e5\u81ea\u5b9a\u4e49\u51fd\u6570\u4e2d\u7684\u95ee\u9898\uff1a\u68c0\u67e5\u8f93\u5165\u548c\u8f93\u51fa\uff1a\u9a8c\u8bc1\u8f93\u5165\u662f\u5426\u6709\u6548\uff0c\u68c0\u67e5\u8f93\u51fa\u662f\u5426\u7b26\u5408\u9884\u671f\u3002\u4f7f\u7528\u8c03\u8bd5\u5668\uff1a\u9010\u884c\u6267\u884c\u4ee3\u7801\u5e76\u68c0\u67e5\u53d8\u91cf\u7684\u503c\u3002\u5355\u5143\u6d4b\u8bd5\uff1a\u7f16\u5199\u81ea\u52a8\u5316\u6d4b\u8bd5\u7528\u4f8b\u6765\u6d4b\u8bd5\u51fd\u6570\u7684\u6b63\u786e\u6027\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241027\/1729990121671d8de95316d.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u8c03\u8bd5\u548c\u6392\u67e5\u81ea\u5b9a\u4e49\u51fd\u6570\u4e2d\u7684\u95ee\u9898\u63d2\u56fe\" alt=\"\u5982\u4f55\u8c03\u8bd5\u548c\u6392\u67e5\u81ea\u5b9a\u4e49\u51fd\u6570\u4e2d\u7684\u95ee\u9898\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u8c03\u8bd5\u548c\u6392\u67e5\u81ea\u5b9a\u4e49\u51fd\u6570\u4e2d\u7684\u95ee\u9898<\/strong><\/p>\n<p><strong>\u4ecb\u7ecd<\/strong><\/p>\n<p>\u81ea\u5b9a\u4e49\u51fd\u6570\u662f\u6269\u5c55 Python \u529f\u80fd\u548c\u7b80\u5316\u4ee3\u7801\u7684\u6709\u7528\u5de5\u5177\u3002\u7136\u800c\uff0c\u5f53\u51fd\u6570\u51fa\u73b0\u95ee\u9898\u65f6\uff0c\u6392\u67e5\u95ee\u9898\u53ef\u80fd\u5177\u6709\u6311\u6218\u6027\u3002\u672c\u6587\u5c06\u6307\u5bfc\u60a8\u9010\u6b65\u8c03\u8bd5\u548c\u6392\u67e5\u81ea\u5b9a\u4e49\u51fd\u6570\u4e2d\u7684\u95ee\u9898\uff0c\u5e76\u63d0\u4f9b\u5b9e\u6218\u6848\u4f8b\u6765\u8bf4\u660e\u3002<\/p>\n<p><strong>\u6b65\u9aa4 1\uff1a\u68c0\u67e5\u8f93\u5165\u548c\u8f93\u51fa<\/strong><\/p>\n<ul>\n<li>\u9a8c\u8bc1\u51fd\u6570\u7684\u8f93\u5165\u662f\u5426\u6709\u6548\u3002\u4f7f\u7528 <code>print()<\/code> \u8bed\u53e5\u6253\u5370\u8f93\u5165\u4ee5\u8fdb\u884c\u68c0\u67e5\u3002<\/li>\n<li>\u68c0\u67e5\u51fd\u6570\u7684\u8f93\u51fa\u662f\u5426\u7b26\u5408\u9884\u671f\u3002<\/li>\n<\/ul>\n<p><strong>\u4ee3\u7801\u793a\u4f8b\uff08\u68c0\u67e5\u8f93\u5165\uff09\uff1a<\/strong><\/p>\n<pre>def add_numbers(a, b):\n    print(f\"Input values: a={a}, b={b}\")<\/pre>\n<p><strong>\u6b65\u9aa4 2\uff1a\u4f7f\u7528\u8c03\u8bd5\u5668<\/strong><\/p>\n<p>Python \u7684\u5185\u7f6e\u8c03\u8bd5\u5668 <code>pdb<\/code> \u5141\u8bb8\u60a8\u9010\u6b65\u6267\u884c\u4ee3\u7801\u5e76\u68c0\u67e5\u53d8\u91cf\u7684\u503c\u3002\u8981\u4f7f\u7528 <code>pdb<\/code>\uff0c\u8bf7\u8f93\u5165\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n<pre>import pdb; pdb.set_trace()<\/pre>\n<p>\u5728\u60a8\u8981\u68c0\u67e5\u4ee3\u7801\u7684\u884c\u4e4b\u524d\u63d2\u5165\u6b64\u884c\u3002\u7136\u540e\uff0c\u4f7f\u7528 <code>n<\/code>\uff08\u4e0b\u4e00\u884c\uff09\u548c <code>s<\/code>\uff08\u5355\u6b65\u6267\u884c\uff09\u547d\u4ee4\u9010\u6b65\u6267\u884c\u4ee3\u7801\u3002<\/p>\n<p><strong>\u4ee3\u7801\u793a\u4f8b\uff08\u4f7f\u7528\u8c03\u8bd5\u5668\uff09\uff1a<\/strong><\/p>\n<pre>def add_numbers(a, b):\n    pdb.set_trace()\n    return a + b<\/pre>\n<p><strong>\u6b65\u9aa4 3\uff1a\u5355\u5143\u6d4b\u8bd5<\/strong><\/p>\n<p>\u5355\u5143\u6d4b\u8bd5\u662f\u4e00\u79cd\u6d4b\u8bd5\u51fd\u6570\u6b63\u786e\u6027\u7684\u81ea\u52a8\u5316\u65b9\u6cd5\u3002\u4f7f\u7528 <code>unittest<\/code> \u6a21\u5757\u7f16\u5199\u6d4b\u8bd5\u7528\u4f8b\uff0c\u5e76\u9488\u5bf9\u5404\u79cd\u8f93\u5165\u503c\u8fd0\u884c\u6d4b\u8bd5\u3002<\/p>\n<p><strong>\u4ee3\u7801\u793a\u4f8b\uff08\u5355\u5143\u6d4b\u8bd5\uff09\uff1a<\/strong><\/p>\n<pre>import unittest\n\nclass TestAddNumbers(unittest.TestCase):\n\n    def test_positive_numbers(self):\n        self.assertEqual(add_numbers(1, 2), 3)\n\n    def test_negative_numbers(self):\n        self.assertEqual(add_numbers(-1, -2), -3)<\/pre>\n<p><strong>\u5b9e\u6218\u6848\u4f8b\uff1a\u8c03\u8bd5\u9519\u8bef\u7684\u51fd\u6570<\/strong><\/p>\n<p>\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a <code>find_min()<\/code> \u51fd\u6570\uff0c\u4f46\u5b83\u6ca1\u6709\u6b63\u786e\u8fd4\u56de\u6700\u5c0f\u503c\u3002<\/p>\n<pre>def find_min(numbers):\n    min_value = numbers[0]\n    for number in numbers:\n        if number &lt; min_value:\n            min_value = number\n    return min_value<\/pre>\n<p><strong>\u95ee\u9898\u6392\u67e5\uff1a<\/strong><\/p>\n<ol>\n<li><strong>\u68c0\u67e5\u8f93\u5165\uff1a<\/strong>\u8f93\u5165\u7684\u6570\u7ec4\u662f\u5426\u4e3a\u7a7a\uff1f<\/li>\n<li><strong>\u4f7f\u7528\u8c03\u8bd5\u5668\uff1a<\/strong>\u5728\u786e\u5b9a\u6700\u5c0f\u503c\u7684\u5faa\u73af\u4e2d\u8bbe\u7f6e\u65ad\u70b9\u4ee5\u68c0\u67e5 <code>min_value<\/code> \u7684\u503c\u3002<\/li>\n<li><strong>\u5355\u5143\u6d4b\u8bd5\uff1a<\/strong>\u7f16\u5199\u6d4b\u8bd5\u7528\u4f8b\u6765\u9488\u5bf9\u5404\u79cd\u8f93\u5165\u503c\u6d4b\u8bd5\u51fd\u6570\u3002<\/li>\n<\/ol>\n<p>\u7ecf\u8fc7\u6392\u67e5\uff0c\u6211\u4eec\u53d1\u73b0\u51fd\u6570\u4e2d\u7684\u95ee\u9898\u662f\u521d\u59cb <code>min_value<\/code> \u7684\u8bbe\u7f6e\u3002\u5c06\u5176\u66f4\u6539\u4e3a <code>float('inf')<\/code> \u4fee\u590d\u4e86\u95ee\u9898\u3002<\/p>\n<p><strong>\u7ed3\u8bba<\/strong><\/p>\n<p>\u901a\u8fc7\u6309\u7167\u8fd9\u4e9b\u6b65\u9aa4\uff0c\u60a8\u53ef\u4ee5\u6709\u6548\u5730\u8c03\u8bd5\u548c\u6392\u67e5\u81ea\u5b9a\u4e49\u51fd\u6570\u4e2d\u7684\u95ee\u9898\u3002\u4f7f\u7528\u8c03\u8bd5\u5668\u3001\u5355\u5143\u6d4b\u8bd5\u548c\u4ed4\u7ec6\u68c0\u67e5\u8f93\u5165\u548c\u8f93\u51fa\uff0c\u60a8\u53ef\u4ee5\u8f7b\u677e\u5730\u9694\u79bb\u95ee\u9898\u5e76\u6062\u590d\u51fd\u6570\u7684\u6b63\u5e38\u5de5\u4f5c\u3002<\/p>\n<p>\u5230\u8fd9\u91cc\uff0c\u6211\u4eec\u4e5f\u5c31\u8bb2\u5b8c\u4e86\u300a\u5982\u4f55\u8c03\u8bd5\u548c\u6392\u67e5\u81ea\u5b9a\u4e49\u51fd\u6570\u4e2d\u7684\u95ee\u9898\u300b\u7684\u5185\u5bb9\u4e86\u3002\u4e2a\u4eba\u8ba4\u4e3a\uff0c\u57fa\u7840\u77e5\u8bc6\u7684\u5b66\u4e60\u548c\u5de9\u56fa\uff0c\u662f\u4e3a\u4e86\u66f4\u597d\u7684\u5c06\u5176\u8fd0\u7528\u5230\u9879\u76ee\u4e2d\uff0c\u6b22\u8fce\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff0c\u5e26\u4f60\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u8c03\u8bd5,\u6392\u67e5\u81ea\u5b9a\u4e49\u51fd\u6570\u7684\u77e5\u8bc6\u70b9\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u8c03\u8bd5\u548c\u6392\u67e5\u81ea\u5b9a\u4e49\u51fd\u6570\u4e2d\u7684\u95ee\u9898 IT\u884c\u4e1a\u76f8\u5bf9\u4e8e\u4e00\u822c\u4f20\u7edf\u884c\u4e1a\uff0c\u53d1\u5c55\u66f4\u65b0\u901f\u5ea6\u66f4\u5feb\uff0c\u4e00\u65e6\u505c\u6b62\u4e86\u5b66\u4e60\uff0c\u5f88\u5feb\u5c31\u4f1a\u88ab\u884c\u4e1a\u6240\u6dd8\u6c70\u3002\u6240\u4ee5\u6211\u4eec\u9700\u8981\u8e0f\u8e0f\u5b9e\u5b9e\u7684\u4e0d\u65ad\u5b66\u4e60\uff0c\u7cbe\u8fdb\u81ea\u5df1\u7684\u6280\u672f\uff0c\u5c24\u5176\u662f\u521d\u5b66\u8005\u3002\u4eca\u5929\u7c73\u4e91\u7ed9\u5927\u5bb6\u6574\u7406\u4e86\u300a\u5982\u4f55\u8c03\u8bd5\u548c\u6392\u67e5\u81ea\u5b9a\u4e49\u51fd\u6570\u4e2d\u7684\u95ee\u9898\u300b\uff0c\u804a\u804a\uff0c\u6211\u4eec\u4e00\u8d77\u6765\u770b\u770b\u5427\uff01 \u5982\u4f55\u8c03\u8bd5\u548c\u6392\u67e5\u81ea\u5b9a\u4e49\u51fd\u6570\u4e2d\u7684\u95ee\u9898\uff1a\u68c0\u67e5\u8f93\u5165\u548c\u8f93\u51fa\uff1a\u9a8c\u8bc1\u8f93\u5165\u662f\u5426\u6709\u6548\uff0c\u68c0\u67e5\u8f93\u51fa\u662f\u5426\u7b26\u5408\u9884\u671f\u3002\u4f7f\u7528\u8c03\u8bd5\u5668\uff1a\u9010\u884c\u6267\u884c\u4ee3\u7801\u5e76\u68c0\u67e5\u53d8\u91cf\u7684\u503c\u3002\u5355\u5143\u6d4b\u8bd5\uff1a\u7f16\u5199\u81ea\u52a8\u5316\u6d4b\u8bd5\u7528\u4f8b\u6765\u6d4b\u8bd5\u51fd\u6570\u7684\u6b63\u786e\u6027\u3002 \u5982\u4f55\u8c03\u8bd5\u548c\u6392\u67e5\u81ea\u5b9a\u4e49\u51fd\u6570\u4e2d\u7684\u95ee\u9898 \u4ecb\u7ecd \u81ea\u5b9a\u4e49\u51fd\u6570\u662f\u6269\u5c55 Python \u529f\u80fd\u548c\u7b80\u5316\u4ee3\u7801\u7684\u6709\u7528\u5de5\u5177\u3002\u7136\u800c\uff0c\u5f53\u51fd\u6570\u51fa\u73b0\u95ee\u9898\u65f6\uff0c\u6392\u67e5\u95ee\u9898\u53ef\u80fd\u5177\u6709\u6311\u6218\u6027\u3002\u672c\u6587\u5c06\u6307\u5bfc\u60a8\u9010\u6b65\u8c03\u8bd5\u548c\u6392\u67e5\u81ea\u5b9a\u4e49\u51fd\u6570\u4e2d\u7684\u95ee\u9898\uff0c\u5e76\u63d0\u4f9b\u5b9e\u6218\u6848\u4f8b\u6765\u8bf4\u660e\u3002 \u6b65\u9aa4 1\uff1a\u68c0\u67e5\u8f93\u5165\u548c\u8f93\u51fa \u9a8c\u8bc1\u51fd\u6570\u7684\u8f93\u5165\u662f\u5426\u6709\u6548\u3002\u4f7f\u7528 print() \u8bed\u53e5\u6253\u5370\u8f93\u5165\u4ee5\u8fdb\u884c\u68c0\u67e5\u3002 \u68c0\u67e5\u51fd\u6570\u7684\u8f93\u51fa\u662f\u5426\u7b26\u5408\u9884\u671f\u3002 \u4ee3\u7801\u793a\u4f8b\uff08\u68c0\u67e5\u8f93\u5165\uff09\uff1a def add_numbers(a, b): print(f&#8221;Input values: a={a}, b={b}&#8221;) \u6b65\u9aa4 2\uff1a\u4f7f\u7528\u8c03\u8bd5\u5668 Python \u7684\u5185\u7f6e\u8c03\u8bd5\u5668 pdb \u5141\u8bb8\u60a8\u9010\u6b65\u6267\u884c\u4ee3\u7801\u5e76\u68c0\u67e5\u53d8\u91cf\u7684\u503c\u3002\u8981\u4f7f\u7528 pdb\uff0c\u8bf7\u8f93\u5165\u4ee5\u4e0b\u5185\u5bb9\uff1a import pdb; pdb.set_trace() \u5728\u60a8\u8981\u68c0\u67e5\u4ee3\u7801\u7684\u884c\u4e4b\u524d\u63d2\u5165\u6b64\u884c\u3002\u7136\u540e\uff0c\u4f7f\u7528 n\uff08\u4e0b\u4e00\u884c\uff09\u548c s\uff08\u5355\u6b65\u6267\u884c\uff09\u547d\u4ee4\u9010\u6b65\u6267\u884c\u4ee3\u7801\u3002 \u4ee3\u7801\u793a\u4f8b\uff08\u4f7f\u7528\u8c03\u8bd5\u5668\uff09\uff1a def add_numbers(a, b): pdb.set_trace() return a + b \u6b65\u9aa4 3\uff1a\u5355\u5143\u6d4b\u8bd5 \u5355\u5143\u6d4b\u8bd5\u662f\u4e00\u79cd\u6d4b\u8bd5\u51fd\u6570\u6b63\u786e\u6027\u7684\u81ea\u52a8\u5316\u65b9\u6cd5\u3002\u4f7f\u7528 unittest \u6a21\u5757\u7f16\u5199\u6d4b\u8bd5\u7528\u4f8b\uff0c\u5e76\u9488\u5bf9\u5404\u79cd\u8f93\u5165\u503c\u8fd0\u884c\u6d4b\u8bd5\u3002 \u4ee3\u7801\u793a\u4f8b\uff08\u5355\u5143\u6d4b\u8bd5\uff09\uff1a import unittest class TestAddNumbers(unittest.TestCase): def [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-48111","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48111","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=48111"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48111\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=48111"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=48111"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=48111"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}