{"id":204872,"date":"2025-05-29T08:04:26","date_gmt":"2025-05-29T00:04:26","guid":{"rendered":"https:\/\/server.hk\/cnblog\/204872\/"},"modified":"2025-05-29T08:04:26","modified_gmt":"2025-05-29T00:04:26","slug":"python-%e5%ad%97%e5%85%b8%e6%9f%a5%e8%af%a2%ef%bc%9a%e4%b8%ba%e4%bb%80%e4%b9%88%e8%be%93%e5%85%a5%e6%9f%a5%e6%89%be%e6%93%8d%e4%bd%9c%e5%90%8e%ef%bc%8c%e5%8d%b3%e4%bd%bf%e5%ad%97%e5%85%b8%e4%b8%ba","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/204872\/","title":{"rendered":"Python \u5b57\u5178\u67e5\u8be2\uff1a\u4e3a\u4ec0\u4e48\u8f93\u5165\u67e5\u627e\u64cd\u4f5c\u540e\uff0c\u5373\u4f7f\u5b57\u5178\u4e3a\u7a7a\uff0c\u4e5f\u4e0d\u4f1a\u8fdb\u5165\u201c\u5b57\u5178\u65e0\u503c\u201d\u6253\u5370\u8bed\u53e5\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>Python \u5b57\u5178\u67e5\u8be2\uff1a\u4e3a\u4ec0\u4e48\u8f93\u5165\u67e5\u627e\u64cd\u4f5c\u540e\uff0c\u5373\u4f7f\u5b57\u5178\u4e3a\u7a7a\uff0c\u4e5f\u4e0d\u4f1a\u8fdb\u5165\u201c\u5b57\u5178\u65e0\u503c\u201d\u6253\u5370\u8bed\u53e5\uff1f<\/h1>\n<p>\u6587\u7ae0\u5c0f\u767d\u4e00\u679a\uff0c\u6b63\u5728\u4e0d\u65ad\u5b66\u4e60\u79ef\u7d2f\u77e5\u8bc6\uff0c\u73b0\u5c06\u5b66\u4e60\u5230\u7684\u77e5\u8bc6\u8bb0\u5f55\u4e00\u4e0b\uff0c\u4e5f\u662f\u5c06\u6211\u7684\u6240\u5f97\u5206\u4eab\u7ed9\u5927\u5bb6\uff01\u800c\u4eca\u5929\u8fd9\u7bc7\u6587\u7ae0\u300aPython \u5b57\u5178\u67e5\u8be2\uff1a\u4e3a\u4ec0\u4e48\u8f93\u5165\u67e5\u627e\u64cd\u4f5c\u540e\uff0c\u5373\u4f7f\u5b57\u5178\u4e3a\u7a7a\uff0c\u4e5f\u4e0d\u4f1a\u8fdb\u5165\u201c\u5b57\u5178\u65e0\u503c\u201d\u6253\u5370\u8bed\u53e5\uff1f\u300b\u5e26\u5927\u5bb6\u6765\u4e86\u89e3\u4e00\u4e0b##content_title##\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u4ece\u800c\u5f25\u8865\u81ea\u5df1\u7684\u4e0d\u8db3\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01<\/p>\n<p><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241118\/1731911452673adf1c7283e.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>python\u65b0\u624b\u5c0f\u95ee\u9898\uff1a\u5b57\u5178\u67e5\u8be2\u6761\u4ef6<\/strong><\/p>\n<p>\u5728 python \u4e2d\uff0c\u4f7f\u7528\u5b57\u5178\u6765\u5b58\u50a8\u952e\u503c\u5bf9\u6570\u636e\u3002\u6700\u8fd1\u4e00\u4f4d\u65b0\u624b\u9047\u5230\u4e00\u4e2a\u95ee\u9898\uff1a\u5728\u8f93\u5165\u67e5\u627e\u64cd\u4f5c\uff08\u201cs\u201d\uff09\u540e\uff0c\u5373\u4f7f\u5b57\u5178\u4e2d\u6ca1\u6709\u76f8\u5e94\u7684\u503c\uff0c\u4e5f\u4e0d\u4f1a\u8fdb\u5165\u201c\u5b57\u5178\u65e0\u503c\u201d\u6253\u5370\u8bed\u53e5\u3002<\/p>\n<p>\u8981\u7406\u89e3\u8fd9\u4e2a\u95ee\u9898\uff0c\u9996\u5148\u8981\u660e\u786e\u5b57\u5178\u7684\u7279\u70b9\uff1a\u5b57\u5178\u901a\u8fc7\u952e\u6765\u67e5\u627e\u6570\u636e\u3002\u5728\u63d0\u4f9b\u7684\u4ee3\u7801\u4e2d\uff0c\u67e5\u627e\u64cd\u4f5c\u662f\u5728\u4e00\u4e2a for \u5faa\u73af\u4e2d\u8fdb\u884c\u7684\uff0c\u904d\u5386\u5b57\u5178\u7684\u952e\u3002<\/p>\n<p>\u5f53\u8f93\u5165\u201cs\u201d\u5e76\u8f93\u5165\u8981\u67e5\u627e\u7684\u503c\u65f6\uff0c\u5982\u679c\u5b57\u5178\u6700\u521d\u4e3a\u7a7a\uff08\u6ca1\u6709\u4efb\u4f55\u952e\uff09\uff0cfor \u5faa\u73af\u5c31\u4e0d\u4f1a\u6267\u884c\u3002\u56e0\u6b64\uff0c\u4e0d\u4f1a\u8fdb\u5165\u201c\u5b57\u5178\u65e0\u503c\u201d\u6253\u5370\u8bed\u53e5\u3002<\/p>\n<p>\u8981\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u5e76\u6b63\u786e\u5904\u7406\u5b57\u5178\u67e5\u8be2\uff0c\u4fee\u6539\u540e\u7684\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>zidian = {}\n\nwhile 1:\n    values1 = input('''\n\u8bf7\u9009\u62e9\u64cd\u4f5c\u6b65\u9aa4\uff1a\n1: \u521b\u5efa\u5b57\u5178\uff08\u8f93\u51fa Y \u5f00\u59cb\uff09\n2: \u67e5\u627e\u5b57\u5178\uff08\u8f93\u51fa S \u5f00\u59cb\uff09\n3: \u9000\u51fa\u7a0b\u5e8f\uff08\u8f93\u51fa N \u7ed3\u675f\uff09\n4: \u7ee7\u7eed\u64cd\u4f5c\uff08\u8f93\u51fa w\uff09\n\u8bf7\u9009\u62e9\u4f60\u7684\u64cd\u4f5c\uff1a\n''')\n\n    if values1.upper()=='Y':\n        while 1:\n            zidian_value = input(\"\u8bf7\u8f93\u5165\u5b57\u5178 Value \u503c\uff1a\")\n            zidian_Key = input(\"\u8bf7\u8f93\u5165\u5b57\u5178 Key \u503c\uff1a\")\n            zidian[zidian_Key] = zidian_value\n            print(\"\u5b57\u5178\u6dfb\u52a0\u6210\u529f\uff0c\u7ee7\u7eed\u6dfb\u52a0\")\n            print(zidian)\n            Y_N = input(\"\u662f\u5426\u7ee7\u7eed\u6dfb\u52a0\u5b57\u5178\uff1fY or N\")\n            if Y_N.upper() == \"Y\":\n                continue\n            else:\n                break\n    elif values1.upper()=='S':\n        input_key = input(\"\u8bf7\u8f93\u5165\u5b57\u5178 key\u503c\uff1a\")\n        try:\n            print(zidian[input_key])\n        except KeyError as e:\n            print('\u5b57\u5178\u4e2d\u4e0d\u5b58\u5728 input_key \u5bf9\u5e94\u7684\u503c')\n    else:\n        print(\"\u6b63\u5728\u9000\u51fa\u7cfb\u7edf,\u8bf7\u7a0d\u5019...\")\n        break<\/pre>\n<p>\u5728\u4fee\u6539\u540e\u7684\u4ee3\u7801\u4e2d\uff0c\u67e5\u627e\u64cd\u4f5c\u4f7f\u7528 try&#8230;except \u5757\u6765\u5904\u7406\u5f02\u5e38\u3002\u5982\u679c\u5b57\u5178\u4e2d\u4e0d\u5305\u542b\u8f93\u5165\u7684\u952e\uff0c\u5b83\u4f1a\u6253\u5370\u4e00\u6761\u6d88\u606f\uff0c\u8bf4\u660e\u201c\u5b57\u5178\u4e2d\u4e0d\u5b58\u5728 input_key \u5bf9\u5e94\u7684\u503c\u201d\u3002<\/p>\n<p>\u7406\u8bba\u8981\u638c\u63e1\uff0c\u5b9e\u64cd\u4e0d\u80fd\u843d\uff01\u4ee5\u4e0a\u5173\u4e8e\u300aPython \u5b57\u5178\u67e5\u8be2\uff1a\u4e3a\u4ec0\u4e48\u8f93\u5165\u67e5\u627e\u64cd\u4f5c\u540e\uff0c\u5373\u4f7f\u5b57\u5178\u4e3a\u7a7a\uff0c\u4e5f\u4e0d\u4f1a\u8fdb\u5165\u201c\u5b57\u5178\u65e0\u503c\u201d\u6253\u5370\u8bed\u53e5\uff1f\u300b\u7684\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u5927\u5bb6\u90fd\u638c\u63e1\u4e86\u5427\uff01\u5982\u679c\u60f3\u8981\u7ee7\u7eed\u63d0\u5347\u81ea\u5df1\u7684\u80fd\u529b\uff0c\u90a3\u4e48\u5c31\u6765\u5173\u6ce8\u516c\u4f17\u53f7\u5427\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python \u5b57\u5178\u67e5\u8be2\uff1a\u4e3a\u4ec0\u4e48\u8f93&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-204872","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/204872","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=204872"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/204872\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=204872"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=204872"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=204872"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}