{"id":205215,"date":"2025-05-29T11:53:00","date_gmt":"2025-05-29T03:53:00","guid":{"rendered":"https:\/\/server.hk\/cnblog\/205215\/"},"modified":"2025-05-29T11:53:00","modified_gmt":"2025-05-29T03:53:00","slug":"python-%e4%b8%ad%e7%9a%84-%e8%bf%90%e7%ae%97%e7%ac%a6%ef%bc%9a%e5%a6%82%e4%bd%95%e8%ae%a1%e7%ae%97%e4%b8%a4%e4%b8%aa%e6%95%b0%e5%ad%97%e7%9b%b8%e9%99%a4%e5%90%8e%e7%9a%84%e4%bd%99%e6%95%b0%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/205215\/","title":{"rendered":"Python \u4e2d\u7684 % \u8fd0\u7b97\u7b26\uff1a\u5982\u4f55\u8ba1\u7b97\u4e24\u4e2a\u6570\u5b57\u76f8\u9664\u540e\u7684\u4f59\u6570\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>Python \u4e2d\u7684 % \u8fd0\u7b97\u7b26\uff1a\u5982\u4f55\u8ba1\u7b97\u4e24\u4e2a\u6570\u5b57\u76f8\u9664\u540e\u7684\u4f59\u6570\uff1f<\/h1>\n<p>\u79ef\u7d2f\u77e5\u8bc6\uff0c\u80dc\u8fc7\u79ef\u84c4\u91d1\u94f6\uff01\u6bd5\u7adf\u5728\u6587\u7ae0\u5f00\u53d1\u7684\u8fc7\u7a0b\u4e2d\uff0c\u4f1a\u9047\u5230\u5404\u79cd\u5404\u6837\u7684\u95ee\u9898\uff0c\u5f80\u5f80\u90fd\u662f\u4e00\u4e9b\u7ec6\u8282\u77e5\u8bc6\u70b9\u8fd8\u6ca1\u6709\u638c\u63e1\u597d\u800c\u5bfc\u81f4\u7684\uff0c\u56e0\u6b64\u57fa\u7840\u77e5\u8bc6\u70b9\u7684\u79ef\u7d2f\u662f\u5f88\u91cd\u8981\u7684\u3002\u4e0b\u9762\u672c\u6587\u300aPython \u4e2d\u7684 % \u8fd0\u7b97\u7b26\uff1a\u5982\u4f55\u8ba1\u7b97\u4e24\u4e2a\u6570\u5b57\u76f8\u9664\u540e\u7684\u4f59\u6570\uff1f\u300b\uff0c\u5c31\u5e26\u5927\u5bb6\u8bb2\u89e3\u4e00\u4e0b\u77e5\u8bc6\u70b9\uff0c\u82e5\u662f\u4f60\u5bf9\u672c\u6587\u611f\u5174\u8da3\uff0c\u6216\u8005\u662f\u60f3\u641e\u61c2\u5176\u4e2d\u67d0\u4e2a\u77e5\u8bc6\u70b9\uff0c\u5c31\u8bf7\u4f60\u7ee7\u7eed\u5f80\u4e0b\u770b\u5427~<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241126\/173259938467455e5875941.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>python \u4e2d\u53d6\u4f59\u6570\u8fd0\u7b97\u7b26 %<\/strong><\/p>\n<p>\u5728 python \u4e2d\uff0c% \u8fd0\u7b97\u7b26\u8868\u793a\u53d6\u4f59\u6570\u64cd\u4f5c\uff0c\u7528\u4e8e\u8ba1\u7b97\u4e24\u4e2a\u6570\u5b57\u76f8\u9664\u540e\u7684\u4f59\u6570\u3002<\/p>\n<p><strong>\u7528\u9014\uff1a<\/strong><\/p>\n<p>\u53d6\u4f59\u6570\u8fd0\u7b97\u7b26 % \u7528\u4e8e\u6c42\u4e00\u4e2a\u6570\u5b57\u9664\u4ee5\u53e6\u4e00\u4e2a\u6570\u5b57\u540e\u5269\u4f59\u7684\u4f59\u6570\u3002\u8bed\u6cd5\u4e3a\uff1a<\/p>\n<pre>result = a % b<\/pre>\n<p>\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li>a \u662f\u88ab\u9664\u6570<\/li>\n<li>b \u662f\u9664\u6570<\/li>\n<li>result \u662f\u8ba1\u7b97\u5f97\u5230\u7684\u4f59\u6570<\/li>\n<\/ul>\n<p><strong>\u4f8b\u5b50\uff1a<\/strong><\/p>\n<pre>a = 5\nb = 3\nresult = a % b\nprint(result)  # \u8f93\u51fa 2<\/pre>\n<p>\u5728\u672c\u4f8b\u4e2d\uff0ca \u9664\u4ee5 b \u7684\u4f59\u6570\u4e3a 2\uff0c\u56e0\u6b64 result \u7684\u503c\u4e3a 2\u3002<\/p>\n<p><strong>\u7406\u89e3\u4f59\u6570\uff1a<\/strong><\/p>\n<p>\u53d6\u4f59\u6570\u64cd\u4f5c\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u7406\u89e3\u4e24\u4e2a\u6570\u5b57\u76f8\u9664\u65f6\u7684\u5269\u4f59\u91cf\u3002\u4f8b\u5982\uff0c\u5982\u679c\u6211\u4eec\u6709 5 \u4e2a\u82f9\u679c\u548c 3 \u4e2a\u4eba\uff0c\u90a3\u4e48\u6bcf\u4eba\u53ef\u4ee5\u5206\u5f97 1 \u4e2a\u82f9\u679c\uff0c\u5269\u4f59 2 \u4e2a\u82f9\u679c\u3002\u4f59\u6570 2 \u8868\u793a\u65e0\u6cd5\u5e73\u5747\u5206\u914d\u7ed9\u6240\u6709\u4eba\u7684\u591a\u4f59\u82f9\u679c\u3002<\/p>\n<p>\u7ec8\u4e8e\u4ecb\u7ecd\u5b8c\u5566\uff01\u5c0f\u4f19\u4f34\u4eec\uff0c\u8fd9\u7bc7\u5173\u4e8e\u300aPython \u4e2d\u7684 % \u8fd0\u7b97\u7b26\uff1a\u5982\u4f55\u8ba1\u7b97\u4e24\u4e2a\u6570\u5b57\u76f8\u9664\u540e\u7684\u4f59\u6570\uff1f\u300b\u7684\u4ecb\u7ecd\u5e94\u8be5\u8ba9\u4f60\u6536\u83b7\u591a\u591a\u4e86\u5427\uff01\u6b22\u8fce\u5927\u5bb6\u6536\u85cf\u6216\u5206\u4eab\u7ed9\u66f4\u591a\u9700\u8981\u5b66\u4e60\u7684\u670b\u53cb\u5427~\u516c\u4f17\u53f7\u4e5f\u4f1a\u53d1\u5e03\u6587\u7ae0\u76f8\u5173\u77e5\u8bc6\uff0c\u5feb\u6765\u5173\u6ce8\u5427\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python \u4e2d\u7684 % \u8fd0\u7b97\u7b26\uff1a&#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-205215","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/205215","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=205215"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/205215\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=205215"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=205215"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=205215"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}