{"id":204148,"date":"2025-05-29T09:04:45","date_gmt":"2025-05-29T01:04:45","guid":{"rendered":"https:\/\/server.hk\/cnblog\/204148\/"},"modified":"2025-05-29T09:04:45","modified_gmt":"2025-05-29T01:04:45","slug":"%e5%a6%82%e4%bd%95%e7%94%a8-python-%e4%bb%a3%e7%a0%81%e5%8c%ba%e5%88%86%e8%be%93%e5%85%a5%e5%86%85%e5%ae%b9%e4%b8%ad%e7%9a%84%e5%ad%97%e6%af%8d%e3%80%81%e6%95%b0%e5%ad%97%e5%92%8c%e6%b1%89%e5%ad%97","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/204148\/","title":{"rendered":"\u5982\u4f55\u7528 Python \u4ee3\u7801\u533a\u5206\u8f93\u5165\u5185\u5bb9\u4e2d\u7684\u5b57\u6bcd\u3001\u6570\u5b57\u548c\u6c49\u5b57\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u5982\u4f55\u7528 Python \u4ee3\u7801\u533a\u5206\u8f93\u5165\u5185\u5bb9\u4e2d\u7684\u5b57\u6bcd\u3001\u6570\u5b57\u548c\u6c49\u5b57\uff1f<\/h1>\n<p>\u5728IT\u884c\u4e1a\u8fd9\u4e2a\u53d1\u5c55\u66f4\u65b0\u901f\u5ea6\u5f88\u5feb\u7684\u884c\u4e1a\uff0c\u53ea\u6709\u4e0d\u505c\u6b62\u7684\u5b66\u4e60\uff0c\u624d\u4e0d\u4f1a\u88ab\u884c\u4e1a\u6240\u6dd8\u6c70\u3002\u5982\u679c\u4f60\u662f\u6587\u7ae0\u5b66\u4e60\u8005\uff0c\u90a3\u4e48\u672c\u6587\u300a\u5982\u4f55\u7528 Python \u4ee3\u7801\u533a\u5206\u8f93\u5165\u5185\u5bb9\u4e2d\u7684\u5b57\u6bcd\u3001\u6570\u5b57\u548c\u6c49\u5b57\uff1f\u300b\u5c31\u5f88\u9002\u5408\u4f60\uff01\u672c\u7bc7\u5185\u5bb9\u4e3b\u8981\u5305\u62ec##content_title##\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241029\/17302135046720f6800e564.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>python \u5224\u65ad\u8f93\u5165\u5185\u5bb9\u4e2d\u5b57\u6bcd\u548c\u6570\u5b57\u7684\u4e2a\u6570<\/strong><\/p>\n<p>\u5728 python \u4e2d\uff0c\u7f16\u5199\u4e00\u4e2a\u7a0b\u5e8f\u6765\u5224\u65ad\u7528\u6237\u8f93\u5165\u7684\u5185\u5bb9\u4e2d\u5305\u542b\u7684\u5b57\u6bcd\u548c\u6570\u5b57\u7684\u4e2a\u6570\u3002<\/p>\n<p><strong>\u539f\u59cb\u4ee3\u7801\uff1a<\/strong><\/p>\n<pre>q = 0\nw = 0\nv = input(\"\u8bf7\u8f93\u5165\u5185\u5bb9&gt;&gt;&gt;\")\nfor item in v:\n    if item.isdigit() == true:\n        q += 1\n    if item in str.isalpha():\n        w += 1\nprint(\"\u4e00\u5171\u8f93\u5165\" + str(q) + \"\u4e2a\u6570\u5b57\u548c\" + str(w) + \"\u5b57\u6bcd\")<\/pre>\n<p><strong>\u95ee\u9898\uff1a<\/strong><\/p>\n<p>\u4e0a\u8ff0\u4ee3\u7801\u5b58\u5728\u4e00\u4e2a\u95ee\u9898\uff1a\u5b83\u5c06\u6c49\u5b57\u4e5f\u89c6\u4e3a\u5b57\u6bcd\u3002\u56e0\u6b64\uff0c\u6211\u4eec\u9700\u8981\u5bf9\u4ee3\u7801\u8fdb\u884c\u4fee\u6539\uff0c\u4ee5\u4fbf\u6392\u9664\u6c49\u5b57\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><\/p>\n<p>\u4fee\u6539\u540e\u7684\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>q = 0\nw = 0\nv = input(\"\u8bf7\u8f93\u5165\uff1a\")\nfor item in v:\n    if item.isalnum():\n        if item.isdecimal():\n            q += 1\n        elif item.isalpha():\n            if item &gt; u'\\u4e00' and item &lt; u'\\u9fa5':     # \u5224\u65ad\u662f\u5426\u662f\u6c49\u5b57\n                pass\n            else:\n                w += 1\n\nprint(\"\u6709%d\u4e2a\u6570\u5b57\uff0c\u6709%d\u4e2a\u5b57\u6bcd\" % (q, w))<\/pre>\n<p>\u8fd9\u6bb5\u4ee3\u7801\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u6392\u9664\u6c49\u5b57\uff1a<\/p>\n<ol>\n<li>\u68c0\u67e5\u5b57\u7b26\u662f\u5426\u5c5e\u4e8e\u5b57\u6bcd\u6570\u5b57 (isalnum())\u3002<\/li>\n<li>\u5982\u679c\u662f\u6570\u5b57 (isdecimal())\uff0c\u5219\u5c06\u5176\u8ba1\u4e3a\u6570\u5b57\u3002<\/li>\n<li>\u5982\u679c\u662f\u5b57\u6bcd (isalpha())\uff0c\u5219\u68c0\u67e5\u5176 unicode \u8303\u56f4\u3002<\/li>\n<li>\u5982\u679c\u4e0d\u5728\u6c49\u5b57 unicode \u8303\u56f4\u4ee5\u5185\uff0c\u5219\u5c06\u5176\u8ba1\u4e3a\u5b57\u6bcd\u3002<\/li>\n<\/ol>\n<p>\u7406\u8bba\u8981\u638c\u63e1\uff0c\u5b9e\u64cd\u4e0d\u80fd\u843d\uff01\u4ee5\u4e0a\u5173\u4e8e\u300a\u5982\u4f55\u7528 Python \u4ee3\u7801\u533a\u5206\u8f93\u5165\u5185\u5bb9\u4e2d\u7684\u5b57\u6bcd\u3001\u6570\u5b57\u548c\u6c49\u5b57\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>\u5982\u4f55\u7528 Python \u4ee3\u7801\u533a\u5206\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-204148","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/204148","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=204148"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/204148\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=204148"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=204148"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=204148"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}