{"id":1140714,"date":"2025-01-08T22:24:05","date_gmt":"2025-01-08T14:24:05","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1140714.html"},"modified":"2025-01-08T22:24:08","modified_gmt":"2025-01-08T14:24:08","slug":"python%e5%a6%82%e4%bd%95%e5%88%a4%e6%96%ad%e4%b8%80%e4%b8%aa%e6%95%b0%e8%83%bd%e5%90%a6%e8%a2%ab%e6%95%b4%e9%99%a4","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1140714.html","title":{"rendered":"python\u5982\u4f55\u5224\u65ad\u4e00\u4e2a\u6570\u80fd\u5426\u88ab\u6574\u9664"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25103633\/a642a261-e8ed-478e-adc8-394e309c2909.webp\" alt=\"python\u5982\u4f55\u5224\u65ad\u4e00\u4e2a\u6570\u80fd\u5426\u88ab\u6574\u9664\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\uff0c\u5224\u65ad\u4e00\u4e2a\u6570\u80fd\u5426\u88ab\u6574\u9664\u7684\u65b9\u6cd5\u4e3b\u8981\u6709\u4ee5\u4e0b\u51e0\u79cd\uff1a\u4f7f\u7528\u53d6\u6a21\u8fd0\u7b97\u7b26\uff08%\uff09\u3001\u4f7f\u7528divmod\u51fd\u6570\u3001\u4f7f\u7528\u6574\u6570\u9664\u6cd5\uff08\/\/\uff09\u3002<\/strong> \u5176\u4e2d\uff0c\u4f7f\u7528\u53d6\u6a21\u8fd0\u7b97\u7b26\u662f\u6700\u5e38\u89c1\u548c\u76f4\u63a5\u7684\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><p><strong>\u53d6\u6a21\u8fd0\u7b97\u7b26\uff08%\uff09<\/strong> \u662fPython\u4e2d\u5224\u65ad\u4e00\u4e2a\u6570\u662f\u5426\u80fd\u88ab\u53e6\u4e00\u4e2a\u6570\u6574\u9664\u7684\u6700\u5e38\u7528\u65b9\u6cd5\u3002\u901a\u8fc7\u8ba1\u7b97\u4e24\u4e2a\u6570\u7684\u4f59\u6570\uff0c\u5982\u679c\u4f59\u6570\u4e3a\u96f6\uff0c\u5219\u8bf4\u660e\u524d\u4e00\u4e2a\u6570\u53ef\u4ee5\u88ab\u540e\u4e00\u4e2a\u6570\u6574\u9664\u3002\u4f8b\u5982\uff0c<code>a % b == 0<\/code>\uff0c\u5982\u679c\u4e3a\u771f\uff0c\u5219a\u80fd\u88abb\u6574\u9664\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u8ba8\u8bba\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u5e76\u63d0\u4f9b\u4ee3\u7801\u793a\u4f8b\u548c\u5b9e\u9645\u5e94\u7528\u573a\u666f\u3002<\/p>\n<\/p>\n<hr>\n<p><h2>\u4e00\u3001\u4f7f\u7528\u53d6\u6a21\u8fd0\u7b97\u7b26\uff08%\uff09<\/h2>\n<\/p>\n<p><p>\u53d6\u6a21\u8fd0\u7b97\u7b26\u662fPython\u4e2d\u6700\u5e38\u7528\u7684\u8fd0\u7b97\u7b26\u4e4b\u4e00\uff0c\u7279\u522b\u9002\u7528\u4e8e\u5224\u65ad\u6574\u9664\u5173\u7cfb\u3002\u53d6\u6a21\u8fd0\u7b97\u7b26\u7684\u4f7f\u7528\u65b9\u6cd5\u975e\u5e38\u7b80\u5355\uff0c\u53ea\u9700\u8981\u5c06\u4e24\u4e2a\u6570\u8fdb\u884c\u53d6\u6a21\u8fd0\u7b97\uff0c\u7136\u540e\u5224\u65ad\u7ed3\u679c\u662f\u5426\u4e3a\u96f6\u3002<\/p>\n<\/p>\n<p><h3>1.1 \u57fa\u672c\u7528\u6cd5<\/h3>\n<\/p>\n<p><p>\u53d6\u6a21\u8fd0\u7b97\u7b26\u7684\u57fa\u672c\u7528\u6cd5\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">a = 10<\/p>\n<p>b = 2<\/p>\n<p>if a % b == 0:<\/p>\n<p>    print(f&quot;{a} \u80fd\u88ab {b} \u6574\u9664&quot;)<\/p>\n<p>else:<\/p>\n<p>    print(f&quot;{a} \u4e0d\u80fd\u88ab {b} \u6574\u9664&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c<code>10 % 2<\/code> \u7684\u7ed3\u679c\u662f <code>0<\/code>\uff0c\u6240\u4ee5 <code>10<\/code> \u80fd\u88ab <code>2<\/code> \u6574\u9664\u3002<\/p>\n<\/p>\n<p><h3>1.2 \u5e94\u7528\u573a\u666f<\/h3>\n<\/p>\n<p><p>\u53d6\u6a21\u8fd0\u7b97\u7b26\u5728\u5f88\u591a\u5b9e\u9645\u5e94\u7528\u573a\u666f\u4e2d\u90fd\u975e\u5e38\u6709\u7528\uff0c\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<ul>\n<li><strong>\u5224\u65ad\u5947\u5076\u6570<\/strong>\uff1a\u4e00\u4e2a\u6570\u80fd\u5426\u88ab <code>2<\/code> \u6574\u9664\u53ef\u4ee5\u7528\u6765\u5224\u65ad\u5b83\u662f\u5947\u6570\u8fd8\u662f\u5076\u6570\u3002<\/li>\n<\/ul>\n<p><pre><code class=\"language-python\">num = 5<\/p>\n<p>if num % 2 == 0:<\/p>\n<p>    print(f&quot;{num} \u662f\u5076\u6570&quot;)<\/p>\n<p>else:<\/p>\n<p>    print(f&quot;{num} \u662f\u5947\u6570&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ul>\n<li><strong>\u5faa\u73af\u5468\u671f<\/strong>\uff1a\u5728\u5faa\u73af\u4e2d\u4f7f\u7528\u53d6\u6a21\u8fd0\u7b97\u7b26\u53ef\u4ee5\u5b9e\u73b0\u67d0\u4e9b\u5468\u671f\u6027\u7684\u64cd\u4f5c\u3002<\/li>\n<\/ul>\n<p><pre><code class=\"language-python\">for i in range(1, 11):<\/p>\n<p>    if i % 3 == 0:<\/p>\n<p>        print(f&quot;{i} \u662f 3 \u7684\u500d\u6570&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ul>\n<li><strong>\u6821\u9a8c\u7801\u8ba1\u7b97<\/strong>\uff1a\u53d6\u6a21\u8fd0\u7b97\u5728\u6821\u9a8c\u7801\u8ba1\u7b97\u4e2d\u4e5f\u6709\u5e7f\u6cdb\u5e94\u7528\uff0c\u4f8b\u5982ISBN\u7801\u7684\u6821\u9a8c\u3002<\/li>\n<\/ul>\n<p><h2>\u4e8c\u3001\u4f7f\u7528divmod\u51fd\u6570<\/h2>\n<\/p>\n<p><p><code>divmod<\/code> \u51fd\u6570\u662fPython\u5185\u7f6e\u7684\u4e00\u4e2a\u975e\u5e38\u6709\u7528\u7684\u51fd\u6570\uff0c\u5b83\u540c\u65f6\u8fd4\u56de\u5546\u548c\u4f59\u6570\u3002\u8fd9\u4e2a\u51fd\u6570\u7684\u597d\u5904\u662f\u53ef\u4ee5\u4e00\u6b21\u6027\u83b7\u5f97\u4e24\u4e2a\u7ed3\u679c\uff0c\u65e2\u53ef\u4ee5\u5224\u65ad\u6574\u9664\u5173\u7cfb\uff0c\u53c8\u53ef\u4ee5\u83b7\u53d6\u5546\u3002<\/p>\n<\/p>\n<p><h3>2.1 \u57fa\u672c\u7528\u6cd5<\/h3>\n<\/p>\n<p><p><code>divmod<\/code> \u51fd\u6570\u7684\u57fa\u672c\u7528\u6cd5\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">a = 10<\/p>\n<p>b = 3<\/p>\n<p>quotient, rem<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>nder = divmod(a, b)<\/p>\n<p>if remainder == 0:<\/p>\n<p>    print(f&quot;{a} \u80fd\u88ab {b} \u6574\u9664\uff0c\u5546\u662f {quotient}&quot;)<\/p>\n<p>else:<\/p>\n<p>    print(f&quot;{a} \u4e0d\u80fd\u88ab {b} \u6574\u9664\uff0c\u5546\u662f {quotient}\uff0c\u4f59\u6570\u662f {remainder}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c<code>divmod(10, 3)<\/code> \u7684\u7ed3\u679c\u662f <code>(3, 1)<\/code>\uff0c\u6240\u4ee5 <code>10<\/code> \u4e0d\u80fd\u88ab <code>3<\/code> \u6574\u9664\uff0c\u5546\u662f <code>3<\/code>\uff0c\u4f59\u6570\u662f <code>1<\/code>\u3002<\/p>\n<\/p>\n<p><h3>2.2 \u5e94\u7528\u573a\u666f<\/h3>\n<\/p>\n<p><p><code>divmod<\/code> \u51fd\u6570\u5728\u4ee5\u4e0b\u573a\u666f\u4e2d\u975e\u5e38\u6709\u7528\uff1a<\/p>\n<\/p>\n<ul>\n<li><strong>\u540c\u65f6\u83b7\u53d6\u5546\u548c\u4f59\u6570<\/strong>\uff1a\u5728\u9700\u8981\u540c\u65f6\u83b7\u53d6\u5546\u548c\u4f59\u6570\u7684\u60c5\u51b5\u4e0b\uff0c<code>divmod<\/code> \u662f\u4e00\u4e2a\u975e\u5e38\u65b9\u4fbf\u7684\u9009\u62e9\u3002<\/li>\n<\/ul>\n<p><pre><code class=\"language-python\">a = 20<\/p>\n<p>b = 6<\/p>\n<p>quotient, remainder = divmod(a, b)<\/p>\n<p>print(f&quot;{a} \u9664\u4ee5 {b} \u7684\u5546\u662f {quotient}\uff0c\u4f59\u6570\u662f {remainder}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ul>\n<li><strong>\u7b80\u5316\u4ee3\u7801<\/strong>\uff1a\u5728\u67d0\u4e9b\u590d\u6742\u8ba1\u7b97\u4e2d\uff0c<code>divmod<\/code> \u53ef\u4ee5\u7b80\u5316\u4ee3\u7801\uff0c\u63d0\u9ad8\u53ef\u8bfb\u6027\u548c\u6548\u7387\u3002<\/li>\n<\/ul>\n<p><pre><code class=\"language-python\">def convert_seconds(seconds):<\/p>\n<p>    minutes, sec = divmod(seconds, 60)<\/p>\n<p>    hours, min = divmod(minutes, 60)<\/p>\n<p>    return hours, min, sec<\/p>\n<p>print(convert_seconds(3661))  # \u8f93\u51fa: (1, 1, 1)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u4e09\u3001\u4f7f\u7528\u6574\u6570\u9664\u6cd5\uff08\/\/\uff09<\/h2>\n<\/p>\n<p><p>\u6574\u6570\u9664\u6cd5\u8fd0\u7b97\u7b26\uff08\/\/\uff09\u8fd4\u56de\u4e24\u4e2a\u6570\u76f8\u9664\u7684\u6574\u6570\u90e8\u5206\uff0c\u867d\u7136\u5b83\u4e0d\u80fd\u76f4\u63a5\u7528\u4e8e\u5224\u65ad\u6574\u9664\u5173\u7cfb\uff0c\u4f46\u53ef\u4ee5\u7ed3\u5408\u5176\u4ed6\u8fd0\u7b97\u7b26\u6765\u5b9e\u73b0\u76f8\u540c\u7684\u529f\u80fd\u3002<\/p>\n<\/p>\n<p><h3>3.1 \u57fa\u672c\u7528\u6cd5<\/h3>\n<\/p>\n<p><p>\u6574\u6570\u9664\u6cd5\u8fd0\u7b97\u7b26\u7684\u57fa\u672c\u7528\u6cd5\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">a = 10<\/p>\n<p>b = 3<\/p>\n<p>if a \/\/ b * b == a:<\/p>\n<p>    print(f&quot;{a} \u80fd\u88ab {b} \u6574\u9664&quot;)<\/p>\n<p>else:<\/p>\n<p>    print(f&quot;{a} \u4e0d\u80fd\u88ab {b} \u6574\u9664&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c<code>10 \/\/ 3 * 3<\/code> \u7684\u7ed3\u679c\u662f <code>9<\/code>\uff0c\u6240\u4ee5 <code>10<\/code> \u4e0d\u80fd\u88ab <code>3<\/code> \u6574\u9664\u3002<\/p>\n<\/p>\n<p><h3>3.2 \u5e94\u7528\u573a\u666f<\/h3>\n<\/p>\n<p><p>\u6574\u6570\u9664\u6cd5\u8fd0\u7b97\u7b26\u5728\u67d0\u4e9b\u7279\u5b9a\u573a\u666f\u4e2d\u4e5f\u975e\u5e38\u6709\u7528\uff1a<\/p>\n<\/p>\n<ul>\n<li><strong>\u5206\u7ec4\u64cd\u4f5c<\/strong>\uff1a\u5728\u6570\u636e\u5904\u7406\u548c\u5206\u6790\u4e2d\uff0c\u6574\u6570\u9664\u6cd5\u53ef\u4ee5\u7528\u4e8e\u5206\u7ec4\u64cd\u4f5c\u3002<\/li>\n<\/ul>\n<p><pre><code class=\"language-python\">data = [1, 2, 3, 4, 5, 6, 7, 8, 9]<\/p>\n<p>grouped_data = [data[i:i+3] for i in range(0, len(data), 3)]<\/p>\n<p>print(grouped_data)  # \u8f93\u51fa: [[1, 2, 3], [4, 5, 6], [7, 8, 9]]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ul>\n<li><strong>\u5206\u9875\u663e\u793a<\/strong>\uff1a\u5728\u5206\u9875\u663e\u793a\u4e2d\uff0c\u6574\u6570\u9664\u6cd5\u53ef\u4ee5\u8ba1\u7b97\u603b\u9875\u6570\u3002<\/li>\n<\/ul>\n<p><pre><code class=\"language-python\">total_items = 95<\/p>\n<p>items_per_page = 10<\/p>\n<p>total_pages = (total_items + items_per_page - 1) \/\/ items_per_page<\/p>\n<p>print(f&quot;\u603b\u9875\u6570: {total_pages}&quot;)  # \u8f93\u51fa: \u603b\u9875\u6570: 10<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u56db\u3001\u5176\u4ed6\u5224\u65ad\u6574\u9664\u7684\u65b9\u6cd5<\/h2>\n<\/p>\n<p><p>\u9664\u4e86\u4e0a\u8ff0\u4e09\u79cd\u5e38\u7528\u65b9\u6cd5\uff0c\u8fd8\u6709\u4e00\u4e9b\u5176\u4ed6\u65b9\u6cd5\u4e5f\u53ef\u4ee5\u7528\u4e8e\u5224\u65ad\u4e00\u4e2a\u6570\u80fd\u5426\u88ab\u6574\u9664\uff0c\u4f8b\u5982\u4f7f\u7528\u4f4d\u8fd0\u7b97\u548c\u6570\u5b66\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><h3>4.1 \u4f7f\u7528\u4f4d\u8fd0\u7b97<\/h3>\n<\/p>\n<p><p>\u4f4d\u8fd0\u7b97\u5728\u67d0\u4e9b\u7279\u5b9a\u60c5\u51b5\u4e0b\u53ef\u4ee5\u7528\u4e8e\u5224\u65ad\u6574\u9664\u5173\u7cfb\uff0c\u4f8b\u5982\u5224\u65ad\u4e00\u4e2a\u6570\u80fd\u5426\u88ab <code>2<\/code> \u7684\u5e42\u6b21\u6574\u9664\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def is_power_of_two(n):<\/p>\n<p>    return (n &amp; (n - 1)) == 0 and n != 0<\/p>\n<p>print(is_power_of_two(8))  # \u8f93\u51fa: True<\/p>\n<p>print(is_power_of_two(10))  # \u8f93\u51fa: False<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>4.2 \u6570\u5b66\u65b9\u6cd5<\/h3>\n<\/p>\n<p><p>\u4e00\u4e9b\u6570\u5b66\u65b9\u6cd5\u4e5f\u53ef\u4ee5\u7528\u4e8e\u5224\u65ad\u6574\u9664\u5173\u7cfb\uff0c\u4f8b\u5982\u4f7f\u7528\u8f97\u8f6c\u76f8\u9664\u6cd5\u5224\u65ad\u6700\u5927\u516c\u7ea6\u6570\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def gcd(a, b):<\/p>\n<p>    while b:<\/p>\n<p>        a, b = b, a % b<\/p>\n<p>    return a<\/p>\n<p>def is_divisible_by_gcd(a, b):<\/p>\n<p>    return a % gcd(a, b) == 0<\/p>\n<p>print(is_divisible_by_gcd(10, 5))  # \u8f93\u51fa: True<\/p>\n<p>print(is_divisible_by_gcd(10, 3))  # \u8f93\u51fa: False<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u603b\u7ed3<\/h2>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u5224\u65ad\u4e00\u4e2a\u6570\u80fd\u5426\u88ab\u6574\u9664\u7684\u65b9\u6cd5\u6709\u5f88\u591a\uff0c\u4f46\u6700\u5e38\u7528\u548c\u6700\u76f4\u63a5\u7684\u65b9\u6cd5\u662f\u4f7f\u7528\u53d6\u6a21\u8fd0\u7b97\u7b26\uff08%\uff09\u3002\u5176\u4ed6\u65b9\u6cd5\u5982divmod\u51fd\u6570\u548c\u6574\u6570\u9664\u6cd5\uff08\/\/\uff09\u4e5f\u6709\u5404\u81ea\u7684\u5e94\u7528\u573a\u666f\u3002\u6b64\u5916\uff0c\u8fd8\u6709\u4e00\u4e9b\u7279\u5b9a\u60c5\u51b5\u4e0b\u7684\u4f4d\u8fd0\u7b97\u548c\u6570\u5b66\u65b9\u6cd5\u53ef\u4ee5\u7528\u4e8e\u5224\u65ad\u6574\u9664\u5173\u7cfb\u3002\u4e86\u89e3\u548c\u638c\u63e1\u8fd9\u4e9b\u65b9\u6cd5\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u5728\u5b9e\u9645\u7f16\u7a0b\u4e2d\u66f4\u52a0\u9ad8\u6548\u5730\u89e3\u51b3\u95ee\u9898\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u4f7f\u7528Python\u5224\u65ad\u4e00\u4e2a\u6570\u662f\u5426\u80fd\u88ab\u53e6\u4e00\u4e2a\u6570\u6574\u9664\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u53d6\u6a21\u8fd0\u7b97\u7b26\uff08%\uff09\u6765\u5224\u65ad\u4e00\u4e2a\u6570\u662f\u5426\u80fd\u88ab\u53e6\u4e00\u4e2a\u6570\u6574\u9664\u3002\u5982\u679c\u4f59\u6570\u4e3a0\uff0c\u5219\u8868\u793a\u53ef\u4ee5\u6574\u9664\u3002\u793a\u4f8b\u5982\u4e0b\uff1a  <\/p>\n<pre><code class=\"language-python\">def is_divisible(num1, num2):\n    return num1 % num2 == 0\n\nprint(is_divisible(10, 2))  # \u8f93\u51fa: True\nprint(is_divisible(10, 3))  # \u8f93\u51fa: False\n<\/code><\/pre>\n<p><strong>\u5728Python\u4e2d\u5982\u4f55\u5904\u7406\u9664\u6570\u4e3a\u96f6\u7684\u60c5\u51b5\uff1f<\/strong><br \/>\u5728\u8fdb\u884c\u6574\u9664\u5224\u65ad\u65f6\uff0c\u9664\u6570\u4e0d\u80fd\u4e3a\u96f6\u3002\u4e3a\u4e86\u907f\u514d\u7a0b\u5e8f\u5d29\u6e83\uff0c\u53ef\u4ee5\u5728\u5224\u65ad\u4e4b\u524d\u6dfb\u52a0\u4e00\u4e2a\u6761\u4ef6\uff0c\u786e\u4fdd\u9664\u6570\u4e0d\u4e3a\u96f6\u3002\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a  <\/p>\n<pre><code class=\"language-python\">def is_divisible(num1, num2):\n    if num2 == 0:\n        return &quot;\u9664\u6570\u4e0d\u80fd\u4e3a\u96f6&quot;\n    return num1 % num2 == 0\n<\/code><\/pre>\n<p><strong>Python\u4e2d\u662f\u5426\u53ef\u4ee5\u5224\u65ad\u591a\u4e2a\u6570\u540c\u65f6\u80fd\u5426\u88ab\u67d0\u4e2a\u6570\u6574\u9664\uff1f<\/strong><br \/>\u53ef\u4ee5\u901a\u8fc7\u5faa\u73af\u904d\u5386\u5217\u8868\u4e2d\u7684\u6bcf\u4e2a\u6570\uff0c\u4f7f\u7528\u53d6\u6a21\u8fd0\u7b97\u7b26\u5224\u65ad\u5b83\u4eec\u662f\u5426\u80fd\u88ab\u6307\u5b9a\u7684\u6570\u6574\u9664\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a  <\/p>\n<pre><code class=\"language-python\">def check_divisibility(numbers, divisor):\n    return [num for num in numbers if num % divisor == 0]\n\nprint(check_divisibility([10, 15, 20, 25], 5))  # \u8f93\u51fa: [10, 15, 20, 25]\n<\/code><\/pre>\n<p>\u8fd9\u79cd\u65b9\u6cd5\u65b9\u4fbf\u7528\u4e8e\u6279\u91cf\u5904\u7406\u591a\u4e2a\u6570\u7684\u6574\u9664\u5224\u65ad\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\uff0c\u5224\u65ad\u4e00\u4e2a\u6570\u80fd\u5426\u88ab\u6574\u9664\u7684\u65b9\u6cd5\u4e3b\u8981\u6709\u4ee5\u4e0b\u51e0\u79cd\uff1a\u4f7f\u7528\u53d6\u6a21\u8fd0\u7b97\u7b26\uff08%\uff09\u3001\u4f7f\u7528divmod\u51fd\u6570\u3001\u4f7f\u7528\u6574 [&hellip;]","protected":false},"author":3,"featured_media":1140717,"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\/1140714"}],"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=1140714"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1140714\/revisions"}],"predecessor-version":[{"id":1140718,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1140714\/revisions\/1140718"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1140717"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1140714"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1140714"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1140714"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}