{"id":1114956,"date":"2025-01-08T18:02:15","date_gmt":"2025-01-08T10:02:15","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1114956.html"},"modified":"2025-01-08T18:02:17","modified_gmt":"2025-01-08T10:02:17","slug":"python3%e4%b8%adint%e5%a6%82%e4%bd%95%e8%bd%ac%e6%8d%a2%e4%b8%balong","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1114956.html","title":{"rendered":"python3\u4e2dint\u5982\u4f55\u8f6c\u6362\u4e3along"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25075922\/3cfe43c8-86df-4ce2-a524-a6e7dad0a78d.webp\" alt=\"python3\u4e2dint\u5982\u4f55\u8f6c\u6362\u4e3along\" \/><\/p>\n<p><p> \u4e00\u3001Python3\u4e2dint\u5982\u4f55\u8f6c\u6362\u4e3along<\/p>\n<\/p>\n<p><p>\u5728Python3\u4e2d\uff0c<strong>int\u7c7b\u578b\u5df2\u7ecf\u5305\u542b\u4e86long\u7c7b\u578b\u7684\u529f\u80fd\u3001\u4e0d\u9700\u8981\u663e\u5f0f\u8f6c\u6362<\/strong>\u3002\u56e0\u4e3aPython3\u7684int\u7c7b\u578b\u5df2\u7ecf\u81ea\u52a8\u5904\u7406\u4e86\u957f\u6574\u6570\u7c7b\u578b\uff0c<strong>\u5728Python3\u4e2d\u4e0d\u518d\u533a\u5206int\u548clong<\/strong>\u3002\u53ea\u8981\u4f60\u4f7f\u7528int\u7c7b\u578b\uff0cPython3\u4f1a\u81ea\u52a8\u5904\u7406\u4efb\u610f\u7cbe\u5ea6\u7684\u6574\u6570\u8fd0\u7b97\u3002\u56e0\u6b64\uff0c\u4f60\u4e0d\u9700\u8981\u8fdb\u884c\u663e\u5f0f\u7684\u8f6c\u6362\u3002<\/p>\n<\/p>\n<p><p>Python3\u4e2d\uff0cint\u7c7b\u578b\u80fd\u591f\u81ea\u52a8\u6269\u5c55\u4ee5\u5904\u7406\u4efb\u610f\u5927\u7684\u6574\u6570\u3002\u6362\u53e5\u8bdd\u8bf4\uff0c\u65e0\u8bba\u6574\u6570\u591a\u5927\uff0cint\u7c7b\u578b\u90fd\u80fd\u591f\u5904\u7406\uff0c\u8fd9\u6837\u4f60\u5c31\u4e0d\u9700\u8981\u518d\u62c5\u5fc3\u8d85\u8fc7\u67d0\u4e2a\u6574\u6570\u9650\u5236\u7684\u95ee\u9898\u3002\u5728Python2\u4e2d\uff0cint\u548clong\u662f\u4e24\u79cd\u4e0d\u540c\u7684\u7c7b\u578b\uff0c\u9700\u8981\u624b\u52a8\u8f6c\u6362\uff0c\u4f46\u5728Python3\u4e2d\u5df2\u7ecf\u7edf\u4e00\u6210\u4e00\u4e2a\u7c7b\u578b\u2014\u2014int\uff0c\u8fd9\u5927\u5927\u7b80\u5316\u4e86\u6574\u6570\u5904\u7406\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001Python2\u4e2d\u7684int\u548clong<\/p>\n<\/p>\n<p><p>\u5728Python2\u4e2d\uff0c\u5b58\u5728int\u548clong\u4e24\u79cd\u6574\u6570\u7c7b\u578b\u3002int\u7c7b\u578b\u7528\u4e8e\u8868\u793a\u8f83\u5c0f\u7684\u6574\u6570\uff0c\u800clong\u7c7b\u578b\u7528\u4e8e\u8868\u793a\u8f83\u5927\u7684\u6574\u6570\u3002\u5f53\u6574\u6570\u8d85\u51faint\u7684\u8303\u56f4\u65f6\uff0c\u9700\u8981\u4f7f\u7528long\u7c7b\u578b\u3002\u5728Python2\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528\u5e26\u6709L\u540e\u7f00\u7684\u6570\u5b57\u6765\u8868\u793along\u7c7b\u578b\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">a = 12345678901234567890L<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728Python2\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>int()<\/code>\u51fd\u6570\u5c06\u4e00\u4e2a\u6570\u503c\u8f6c\u6362\u4e3aint\u7c7b\u578b\uff0c\u4f7f\u7528<code>long()<\/code>\u51fd\u6570\u5c06\u4e00\u4e2a\u6570\u503c\u8f6c\u6362\u4e3along\u7c7b\u578b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">a = int(123)<\/p>\n<p>b = long(12345678901234567890)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e09\u3001Python3\u4e2d\u7684int\u7c7b\u578b<\/p>\n<\/p>\n<p><p>\u5728Python3\u4e2d\uff0cint\u7c7b\u578b\u5df2\u7ecf\u7edf\u4e00\u4e86int\u548clong\u7c7b\u578b\uff0c\u81ea\u52a8\u5904\u7406\u4efb\u610f\u5927\u7684\u6574\u6570\u3002\u56e0\u6b64\uff0c\u4e0d\u9700\u8981\u8fdb\u884c\u663e\u5f0f\u7684\u8f6c\u6362\u3002\u4f60\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528int\u7c7b\u578b\u5904\u7406\u5927\u6574\u6570\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">a = 1234567890123456789012345678901234567890<\/p>\n<p>print(a)  # \u8f93\u51fa: 1234567890123456789012345678901234567890<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>Python3\u7684int\u7c7b\u578b\u53ef\u4ee5\u81ea\u52a8\u6269\u5c55\uff0c\u4ee5\u5904\u7406\u4efb\u610f\u7cbe\u5ea6\u7684\u6574\u6570<\/strong>\u3002\u5f53\u4f60\u4f7f\u7528\u975e\u5e38\u5927\u7684\u6574\u6570\u65f6\uff0cPython3\u4f1a\u81ea\u52a8\u5904\u7406\u5b83\u4eec\uff0c\u65e0\u9700\u8fdb\u884c\u4efb\u4f55\u8f6c\u6362\u3002\u8fd9\u4f7f\u5f97\u7f16\u7a0b\u66f4\u52a0\u65b9\u4fbf\u548c\u7b80\u6d01\u3002<\/p>\n<\/p>\n<p><p>\u56db\u3001\u4f7f\u7528int\u7c7b\u578b\u5904\u7406\u5927\u6574\u6570<\/p>\n<\/p>\n<p><p>\u5728Python3\u4e2d\uff0cint\u7c7b\u578b\u53ef\u4ee5\u5904\u7406\u975e\u5e38\u5927\u7684\u6574\u6570\uff0c\u56e0\u6b64\u4f60\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u5b83\u6765\u8fdb\u884c\u5927\u6574\u6570\u8fd0\u7b97\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">a = 1234567890123456789012345678901234567890<\/p>\n<p>b = 9876543210987654321098765432109876543210<\/p>\n<p>c = a + b<\/p>\n<p>print(c)  # \u8f93\u51fa: 11111111101111111110111111111011111111100<\/p>\n<p>d = a * b<\/p>\n<p>print(d)  # \u8f93\u51fa: 121932631356500531591068431825826683223741197264284390388520197442389210<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u5230\uff0cPython3\u7684int\u7c7b\u578b\u53ef\u4ee5\u5904\u7406\u975e\u5e38\u5927\u7684\u6574\u6570\uff0c\u5e76\u8fdb\u884c\u52a0\u6cd5\u548c\u4e58\u6cd5\u8fd0\u7b97\u3002<\/p>\n<\/p>\n<p><p>\u4e94\u3001\u6027\u80fd\u4e0e\u5185\u5b58\u7ba1\u7406<\/p>\n<\/p>\n<p><p>\u867d\u7136Python3\u7684int\u7c7b\u578b\u53ef\u4ee5\u5904\u7406\u4efb\u610f\u5927\u7684\u6574\u6570\uff0c\u4f46\u5728\u5904\u7406\u975e\u5e38\u5927\u7684\u6574\u6570\u65f6\uff0c\u6027\u80fd\u548c\u5185\u5b58\u7ba1\u7406\u53ef\u80fd\u4f1a\u53d7\u5230\u5f71\u54cd\u3002\u5904\u7406\u5927\u6574\u6570\u9700\u8981\u66f4\u591a\u7684\u8ba1\u7b97\u8d44\u6e90\u548c\u5185\u5b58\u7a7a\u95f4\uff0c\u56e0\u6b64\u5728\u7f16\u5199\u7a0b\u5e8f\u65f6\u9700\u8981\u6ce8\u610f\u6027\u80fd\u548c\u5185\u5b58\u7ba1\u7406\u3002<\/p>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u7684\u7a0b\u5e8f\u9700\u8981\u5904\u7406\u975e\u5e38\u5927\u7684\u6574\u6570\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528\u4e00\u4e9b\u4f18\u5316\u6280\u5de7\uff0c\u4f8b\u5982\u4f7f\u7528\u66f4\u52a0\u9ad8\u6548\u7684\u7b97\u6cd5\u6216\u6570\u636e\u7ed3\u6784\uff0c\u6216\u8005\u4f7f\u7528Python\u7684\u7b2c\u4e09\u65b9\u5e93\uff0c\u5982<code>gmpy2<\/code>\uff0c\u4ee5\u63d0\u9ad8\u6027\u80fd\u3002<\/p>\n<\/p>\n<p><p>\u516d\u3001\u603b\u7ed3<\/p>\n<\/p>\n<p><p>\u5728Python3\u4e2d\uff0cint\u7c7b\u578b\u5df2\u7ecf\u5305\u542b\u4e86long\u7c7b\u578b\u7684\u529f\u80fd\uff0c\u4e0d\u9700\u8981\u663e\u5f0f\u8f6c\u6362\u3002Python3\u7684int\u7c7b\u578b\u53ef\u4ee5\u81ea\u52a8\u5904\u7406\u4efb\u610f\u5927\u7684\u6574\u6570\uff0c\u8fd9\u5927\u5927\u7b80\u5316\u4e86\u6574\u6570\u5904\u7406\uff0c\u4f7f\u5f97\u7f16\u7a0b\u66f4\u52a0\u65b9\u4fbf\u548c\u7b80\u6d01\u3002\u5728\u5904\u7406\u5927\u6574\u6570\u65f6\uff0c\u9700\u8981\u6ce8\u610f\u6027\u80fd\u548c\u5185\u5b58\u7ba1\u7406\uff0c\u4ee5\u786e\u4fdd\u7a0b\u5e8f\u7684\u9ad8\u6548\u8fd0\u884c\u3002\u901a\u8fc7\u5408\u7406\u7684\u4f18\u5316\u548c\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93\uff0c\u53ef\u4ee5\u8fdb\u4e00\u6b65\u63d0\u9ad8\u5904\u7406\u5927\u6574\u6570\u7684\u6027\u80fd\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5728Python 3\u4e2d\uff0cint\u548clong\u4e4b\u95f4\u6709\u4ec0\u4e48\u533a\u522b\uff1f<\/strong><br \/>\u5728Python 3\u4e2d\uff0cint\u7c7b\u578b\u5df2\u7ecf\u5408\u5e76\u4e86Python 2\u4e2d\u7684int\u548clong\u7c7b\u578b\u3002\u56e0\u6b64\uff0cPython 3\u7684int\u53ef\u4ee5\u8868\u793a\u4efb\u610f\u5927\u5c0f\u7684\u6574\u6570\uff0c\u800c\u4e0d\u518d\u9700\u8981\u4f7f\u7528long\u7c7b\u578b\u3002\u7528\u6237\u53ea\u9700\u4f7f\u7528int\u7c7b\u578b\u6765\u5904\u7406\u5927\u6574\u6570\uff0c\u800c\u65e0\u9700\u8003\u8651\u7c7b\u578b\u8f6c\u6362\u7684\u95ee\u9898\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Python 3\u4e2d\u5904\u7406\u5927\u6574\u6570\uff1f<\/strong><br \/>\u5728Python 3\u4e2d\uff0c\u60a8\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528int\u7c7b\u578b\u6765\u5904\u7406\u5927\u6574\u6570\u3002\u65e0\u8bba\u662f\u5c0f\u6570\u8fd8\u662f\u5927\u6570\uff0c\u90fd\u53ef\u4ee5\u4f7f\u7528\u76f8\u540c\u7684int\u7c7b\u578b\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528<code>x = 123456789012345678901234567890<\/code>\u6765\u5b9a\u4e49\u4e00\u4e2a\u5927\u6574\u6570\uff0c\u5e76\u5728\u540e\u7eed\u7684\u8ba1\u7b97\u4e2d\u4f7f\u7528\u5b83\u3002<\/p>\n<p><strong>\u5728Python 2\u4e2d\uff0c\u5982\u4f55\u5c06int\u8f6c\u6362\u4e3along\uff1f<\/strong><br \/>\u5728Python 2\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u7b80\u5355\u5730\u5c06int\u4f20\u9012\u7ed9long\u6784\u9020\u51fd\u6570\u6765\u8fdb\u884c\u8f6c\u6362\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528<code>long_value = long(int_value)<\/code>\u6765\u5c06\u4e00\u4e2aint\u8f6c\u6362\u4e3along\u3002\u8fd9\u5728Python 2\u4e2d\u662f\u6709\u7528\u7684\uff0c\u4f46\u5728Python 3\u4e2d\u5219\u4e0d\u518d\u9700\u8981\u8003\u8651\u6b64\u95ee\u9898\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u4e00\u3001Python3\u4e2dint\u5982\u4f55\u8f6c\u6362\u4e3along \u5728Python3\u4e2d\uff0cint\u7c7b\u578b\u5df2\u7ecf\u5305\u542b\u4e86long\u7c7b\u578b\u7684\u529f\u80fd\u3001\u4e0d\u9700 [&hellip;]","protected":false},"author":3,"featured_media":1114960,"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\/1114956"}],"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=1114956"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1114956\/revisions"}],"predecessor-version":[{"id":1114964,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1114956\/revisions\/1114964"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1114960"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1114956"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1114956"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1114956"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}