{"id":1117994,"date":"2025-01-08T18:31:13","date_gmt":"2025-01-08T10:31:13","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1117994.html"},"modified":"2025-01-08T18:31:15","modified_gmt":"2025-01-08T10:31:15","slug":"python%e5%a6%82%e4%bd%95%e8%a1%a8%e7%a4%ba%e5%85%ab%e8%bf%9b%e5%88%b6%e7%9a%84%e6%95%b0123","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1117994.html","title":{"rendered":"python\u5982\u4f55\u8868\u793a\u516b\u8fdb\u5236\u7684\u6570123"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25081649\/7f8470c9-5fb3-4903-9319-b7bc33f09dd0.webp\" alt=\"python\u5982\u4f55\u8868\u793a\u516b\u8fdb\u5236\u7684\u6570123\" \/><\/p>\n<p><p> <strong>Python\u8868\u793a\u516b\u8fdb\u5236\u6570123\u7684\u65b9\u6cd5\u6709\uff1a\u4f7f\u7528\u524d\u7f00&#39;0o&#39;\u3001\u4f7f\u7528\u5185\u7f6e\u51fd\u6570oct()\u3001\u4f7f\u7528\u81ea\u5b9a\u4e49\u51fd\u6570\u8fdb\u884c\u8f6c\u6362\u3002<\/strong><\/p>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u516b\u8fdb\u5236\u6570\u53ef\u4ee5\u901a\u8fc7\u5728\u6570\u5b57\u524d\u52a0\u4e0a\u524d\u7f00\u201c0o\u201d\u6216\u201c0O\u201d\u6765\u8868\u793a\u3002\u4f8b\u5982\uff0c\u8981\u8868\u793a\u516b\u8fdb\u5236\u6570123\uff0c\u53ef\u4ee5\u5199\u4f5c\u201c0o123\u201d\u3002\u8fd9\u79cd\u65b9\u6cd5\u5728Python 3\u4e2d\u662f\u6807\u51c6\u7684\u516b\u8fdb\u5236\u6570\u8868\u793a\u65b9\u5f0f\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u8be6\u7ec6\u7684\u63cf\u8ff0\uff1a<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528\u524d\u7f00\u20180o\u2019\u8868\u793a\u516b\u8fdb\u5236\u6570<\/h3>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u516b\u8fdb\u5236\u6570\u53ef\u4ee5\u901a\u8fc7\u5728\u6570\u503c\u524d\u52a0\u4e0a\u524d\u7f00\u201c0o\u201d\u6216\u201c0O\u201d\u6765\u8868\u793a\u3002\u8fd9\u662f\u6700\u76f4\u63a5\u548c\u7b80\u5355\u7684\u65b9\u6cd5\u3002\u6bd4\u5982\uff0c\u8981\u8868\u793a\u516b\u8fdb\u5236\u6570123\uff0c\u53ef\u4ee5\u5199\u4f5c\u201c0o123\u201d\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">octal_number = 0o123<\/p>\n<p>print(octal_number)  # \u8f93\u51fa\u7ed3\u679c\u4e3a83<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c0o123\u662f\u516b\u8fdb\u5236\u6570\uff0c\u8f6c\u6362\u4e3a\u5341\u8fdb\u5236\u6570\u65f6\u7684\u503c\u4e3a83\u3002Python\u4f1a\u81ea\u52a8\u8bc6\u522b\u524d\u7f00\u201c0o\u201d\u5e76\u5c06\u5176\u89c6\u4e3a\u516b\u8fdb\u5236\u6570\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528\u5185\u7f6e\u51fd\u6570oct()\u8fdb\u884c\u8f6c\u6362<\/h3>\n<\/p>\n<p><p>Python\u63d0\u4f9b\u4e86\u4e00\u4e2a\u5185\u7f6e\u51fd\u6570<code>oct()<\/code>\uff0c\u53ef\u4ee5\u5c06\u6574\u6570\u8f6c\u6362\u4e3a\u516b\u8fdb\u5236\u5b57\u7b26\u4e32\u3002\u8fd9\u4e2a\u51fd\u6570\u63a5\u53d7\u4e00\u4e2a\u6574\u6570\u4f5c\u4e3a\u53c2\u6570\uff0c\u5e76\u8fd4\u56de\u8868\u793a\u8be5\u6574\u6570\u7684\u516b\u8fdb\u5236\u5b57\u7b26\u4e32\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">decimal_number = 83<\/p>\n<p>octal_string = oct(decimal_number)<\/p>\n<p>print(octal_string)  # \u8f93\u51fa\u7ed3\u679c\u4e3a &#39;0o123&#39;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c<code>oct(83)<\/code>\u8fd4\u56de\u7684\u7ed3\u679c\u662f\u8868\u793a\u6574\u657083\u7684\u516b\u8fdb\u5236\u5b57\u7b26\u4e32\u201c0o123\u201d\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528\u81ea\u5b9a\u4e49\u51fd\u6570\u8fdb\u884c\u8f6c\u6362<\/h3>\n<\/p>\n<p><p>\u9664\u4e86\u4f7f\u7528\u524d\u7f00\u201c0o\u201d\u548c\u5185\u7f6e\u51fd\u6570<code>oct()<\/code>\u5916\uff0c\u8fd8\u53ef\u4ee5\u7f16\u5199\u81ea\u5b9a\u4e49\u51fd\u6570\u5c06\u6574\u6570\u8f6c\u6362\u4e3a\u516b\u8fdb\u5236\u8868\u793a\u3002\u8fd9\u5bf9\u4e8e\u7406\u89e3\u516b\u8fdb\u5236\u6570\u7684\u6784\u9020\u8fc7\u7a0b\u975e\u5e38\u6709\u5e2e\u52a9\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def decimal_to_octal(decimal_number):<\/p>\n<p>    if decimal_number == 0:<\/p>\n<p>        return &#39;0o0&#39;<\/p>\n<p>    octal_digits = []<\/p>\n<p>    while decimal_number &gt; 0:<\/p>\n<p>        octal_digits.append(str(decimal_number % 8))<\/p>\n<p>        decimal_number \/\/= 8<\/p>\n<p>    octal_digits.reverse()<\/p>\n<p>    return &#39;0o&#39; + &#39;&#39;.join(octal_digits)<\/p>\n<h2><strong>\u4f7f\u7528\u81ea\u5b9a\u4e49\u51fd\u6570\u8fdb\u884c\u8f6c\u6362<\/strong><\/h2>\n<p>decimal_number = 83<\/p>\n<p>octal_string = decimal_to_octal(decimal_number)<\/p>\n<p>print(octal_string)  # \u8f93\u51fa\u7ed3\u679c\u4e3a &#39;0o123&#39;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u81ea\u5b9a\u4e49\u51fd\u6570<code>decimal_to_octal<\/code>\u5c06\u6574\u657083\u8f6c\u6362\u4e3a\u516b\u8fdb\u5236\u5b57\u7b26\u4e32\u201c0o123\u201d\u3002\u8be5\u51fd\u6570\u901a\u8fc7\u4e0d\u65ad\u5c06\u6574\u6570\u9664\u4ee58\u5e76\u8bb0\u5f55\u4f59\u6570\uff0c\u6700\u540e\u5c06\u8fd9\u4e9b\u4f59\u6570\u7ec4\u5408\u6210\u516b\u8fdb\u5236\u6570\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u516b\u8fdb\u5236\u6570\u7684\u5e94\u7528\u573a\u666f<\/h3>\n<\/p>\n<p><p>\u516b\u8fdb\u5236\u6570\u5728\u8ba1\u7b97\u673a\u79d1\u5b66\u548c\u6570\u5b57\u7535\u5b50\u5b66\u4e2d\u6709\u7740\u5e7f\u6cdb\u7684\u5e94\u7528\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u7684\u5e94\u7528\u573a\u666f\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u6587\u4ef6\u6743\u9650\u8868\u793a<\/strong>\uff1a\u5728Unix\u548cLinux\u64cd\u4f5c\u7cfb\u7edf\u4e2d\uff0c\u6587\u4ef6\u6743\u9650\u901a\u5e38\u4f7f\u7528\u516b\u8fdb\u5236\u6570\u8868\u793a\u3002\u4f8b\u5982\uff0c\u6587\u4ef6\u6743\u9650\u201crwxr-xr-x\u201d\u5bf9\u5e94\u7684\u516b\u8fdb\u5236\u6570\u662f0755\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5185\u5b58\u5730\u5740\u8868\u793a<\/strong>\uff1a\u5728\u67d0\u4e9b\u4f4e\u7ea7\u7f16\u7a0b\u4e2d\uff0c\u516b\u8fdb\u5236\u6570\u7528\u4e8e\u8868\u793a\u5185\u5b58\u5730\u5740\u548c\u5176\u4ed6\u786c\u4ef6\u76f8\u5173\u4fe1\u606f\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u538b\u7f29\u548c\u5b58\u50a8\u6570\u636e<\/strong>\uff1a\u516b\u8fdb\u5236\u6570\u5728\u67d0\u4e9b\u6570\u636e\u538b\u7f29\u548c\u5b58\u50a8\u683c\u5f0f\u4e2d\u88ab\u5e7f\u6cdb\u4f7f\u7528\uff0c\u56e0\u4e3a\u5b83\u4eec\u53ef\u4ee5\u66f4\u7d27\u51d1\u5730\u8868\u793a\u6570\u636e\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u4e94\u3001\u516b\u8fdb\u5236\u6570\u4e0e\u5176\u4ed6\u8fdb\u5236\u6570\u7684\u8f6c\u6362<\/h3>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u53ef\u80fd\u9700\u8981\u5c06\u516b\u8fdb\u5236\u6570\u8f6c\u6362\u4e3a\u5176\u4ed6\u8fdb\u5236\u6570\uff08\u5982\u4e8c\u8fdb\u5236\u6570\u3001\u5341\u8fdb\u5236\u6570\u3001\u5341\u516d\u8fdb\u5236\u6570\uff09\u6216\u53cd\u4e4b\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u7528\u7684\u8f6c\u6362\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<p><h4>1. \u516b\u8fdb\u5236\u6570\u8f6c\u6362\u4e3a\u4e8c\u8fdb\u5236\u6570<\/h4>\n<\/p>\n<p><p>\u8981\u5c06\u516b\u8fdb\u5236\u6570\u8f6c\u6362\u4e3a\u4e8c\u8fdb\u5236\u6570\uff0c\u53ef\u4ee5\u9996\u5148\u5c06\u5176\u8f6c\u6362\u4e3a\u5341\u8fdb\u5236\u6570\uff0c\u7136\u540e\u518d\u5c06\u5341\u8fdb\u5236\u6570\u8f6c\u6362\u4e3a\u4e8c\u8fdb\u5236\u6570\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">octal_number = 0o123<\/p>\n<p>decimal_number = int(octal_number)<\/p>\n<p>binary_string = bin(decimal_number)<\/p>\n<p>print(binary_string)  # \u8f93\u51fa\u7ed3\u679c\u4e3a &#39;0b1010011&#39;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u9996\u5148\u5c06\u516b\u8fdb\u5236\u6570\u201c0o123\u201d\u8f6c\u6362\u4e3a\u5341\u8fdb\u5236\u657083\uff0c\u7136\u540e\u4f7f\u7528<code>bin()<\/code>\u51fd\u6570\u5c06\u5176\u8f6c\u6362\u4e3a\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32\u201c0b1010011\u201d\u3002<\/p>\n<\/p>\n<p><h4>2. \u516b\u8fdb\u5236\u6570\u8f6c\u6362\u4e3a\u5341\u516d\u8fdb\u5236\u6570<\/h4>\n<\/p>\n<p><p>\u8981\u5c06\u516b\u8fdb\u5236\u6570\u8f6c\u6362\u4e3a\u5341\u516d\u8fdb\u5236\u6570\uff0c\u53ef\u4ee5\u9996\u5148\u5c06\u5176\u8f6c\u6362\u4e3a\u5341\u8fdb\u5236\u6570\uff0c\u7136\u540e\u518d\u5c06\u5341\u8fdb\u5236\u6570\u8f6c\u6362\u4e3a\u5341\u516d\u8fdb\u5236\u6570\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">octal_number = 0o123<\/p>\n<p>decimal_number = int(octal_number)<\/p>\n<p>hex_string = hex(decimal_number)<\/p>\n<p>print(hex_string)  # \u8f93\u51fa\u7ed3\u679c\u4e3a &#39;0x53&#39;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u9996\u5148\u5c06\u516b\u8fdb\u5236\u6570\u201c0o123\u201d\u8f6c\u6362\u4e3a\u5341\u8fdb\u5236\u657083\uff0c\u7136\u540e\u4f7f\u7528<code>hex()<\/code>\u51fd\u6570\u5c06\u5176\u8f6c\u6362\u4e3a\u5341\u516d\u8fdb\u5236\u5b57\u7b26\u4e32\u201c0x53\u201d\u3002<\/p>\n<\/p>\n<p><h4>3. \u4e8c\u8fdb\u5236\u6570\u8f6c\u6362\u4e3a\u516b\u8fdb\u5236\u6570<\/h4>\n<\/p>\n<p><p>\u8981\u5c06\u4e8c\u8fdb\u5236\u6570\u8f6c\u6362\u4e3a\u516b\u8fdb\u5236\u6570\uff0c\u53ef\u4ee5\u9996\u5148\u5c06\u5176\u8f6c\u6362\u4e3a\u5341\u8fdb\u5236\u6570\uff0c\u7136\u540e\u518d\u5c06\u5341\u8fdb\u5236\u6570\u8f6c\u6362\u4e3a\u516b\u8fdb\u5236\u6570\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">binary_number = 0b1010011<\/p>\n<p>decimal_number = int(binary_number)<\/p>\n<p>octal_string = oct(decimal_number)<\/p>\n<p>print(octal_string)  # \u8f93\u51fa\u7ed3\u679c\u4e3a &#39;0o123&#39;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u9996\u5148\u5c06\u4e8c\u8fdb\u5236\u6570\u201c0b1010011\u201d\u8f6c\u6362\u4e3a\u5341\u8fdb\u5236\u657083\uff0c\u7136\u540e\u4f7f\u7528<code>oct()<\/code>\u51fd\u6570\u5c06\u5176\u8f6c\u6362\u4e3a\u516b\u8fdb\u5236\u5b57\u7b26\u4e32\u201c0o123\u201d\u3002<\/p>\n<\/p>\n<p><h4>4. \u5341\u516d\u8fdb\u5236\u6570\u8f6c\u6362\u4e3a\u516b\u8fdb\u5236\u6570<\/h4>\n<\/p>\n<p><p>\u8981\u5c06\u5341\u516d\u8fdb\u5236\u6570\u8f6c\u6362\u4e3a\u516b\u8fdb\u5236\u6570\uff0c\u53ef\u4ee5\u9996\u5148\u5c06\u5176\u8f6c\u6362\u4e3a\u5341\u8fdb\u5236\u6570\uff0c\u7136\u540e\u518d\u5c06\u5341\u8fdb\u5236\u6570\u8f6c\u6362\u4e3a\u516b\u8fdb\u5236\u6570\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">hex_number = 0x53<\/p>\n<p>decimal_number = int(hex_number)<\/p>\n<p>octal_string = oct(decimal_number)<\/p>\n<p>print(octal_string)  # \u8f93\u51fa\u7ed3\u679c\u4e3a &#39;0o123&#39;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u9996\u5148\u5c06\u5341\u516d\u8fdb\u5236\u6570\u201c0x53\u201d\u8f6c\u6362\u4e3a\u5341\u8fdb\u5236\u657083\uff0c\u7136\u540e\u4f7f\u7528<code>oct()<\/code>\u51fd\u6570\u5c06\u5176\u8f6c\u6362\u4e3a\u516b\u8fdb\u5236\u5b57\u7b26\u4e32\u201c0o123\u201d\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u5904\u7406\u516b\u8fdb\u5236\u6570\u7684\u6ce8\u610f\u4e8b\u9879<\/h3>\n<\/p>\n<p><p>\u5728\u5904\u7406\u516b\u8fdb\u5236\u6570\u65f6\uff0c\u9700\u8981\u6ce8\u610f\u4ee5\u4e0b\u51e0\u70b9\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u524d\u7f00\u201c0o\u201d\u6216\u201c0O\u201d<\/strong>\uff1a\u5728Python\u4e2d\uff0c\u516b\u8fdb\u5236\u6570\u5fc5\u987b\u4f7f\u7528\u524d\u7f00\u201c0o\u201d\u6216\u201c0O\u201d\u8868\u793a\uff0c\u5426\u5219\u4f1a\u88ab\u89c6\u4e3a\u5341\u8fdb\u5236\u6570\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u907f\u514d\u6df7\u6dc6<\/strong>\uff1a\u5728\u7f16\u5199\u4ee3\u7801\u65f6\uff0c\u8981\u786e\u4fdd\u6b63\u786e\u533a\u5206\u516b\u8fdb\u5236\u6570\u3001\u4e8c\u8fdb\u5236\u6570\u3001\u5341\u8fdb\u5236\u6570\u548c\u5341\u516d\u8fdb\u5236\u6570\uff0c\u907f\u514d\u6df7\u6dc6\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8f93\u5165\u9a8c\u8bc1<\/strong>\uff1a\u5728\u5904\u7406\u7528\u6237\u8f93\u5165\u7684\u516b\u8fdb\u5236\u6570\u65f6\uff0c\u8981\u8fdb\u884c\u8f93\u5165\u9a8c\u8bc1\uff0c\u786e\u4fdd\u8f93\u5165\u7684\u6570\u503c\u5408\u6cd5\u4e14\u7b26\u5408\u516b\u8fdb\u5236\u6570\u7684\u89c4\u5219\uff08\u5373\u6bcf\u4e2a\u4f4d\u7684\u6570\u503c\u5e94\u57280\u52307\u4e4b\u95f4\uff09\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u4e03\u3001\u516b\u8fdb\u5236\u6570\u5728Python\u4e2d\u7684\u9ad8\u7ea7\u5e94\u7528<\/h3>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u516b\u8fdb\u5236\u6570\u4e0d\u4ec5\u7528\u4e8e\u57fa\u672c\u7684\u6570\u503c\u8868\u793a\uff0c\u8fd8\u53ef\u4ee5\u5728\u4e00\u4e9b\u9ad8\u7ea7\u5e94\u7528\u4e2d\u53d1\u6325\u4f5c\u7528\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><h4>1. \u6587\u4ef6\u6743\u9650\u8bbe\u7f6e<\/h4>\n<\/p>\n<p><p>\u5728Unix\u548cLinux\u64cd\u4f5c\u7cfb\u7edf\u4e2d\uff0c\u6587\u4ef6\u6743\u9650\u901a\u5e38\u4f7f\u7528\u516b\u8fdb\u5236\u6570\u8868\u793a\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff0c\u7528\u4e8e\u8bbe\u7f6e\u6587\u4ef6\u6743\u9650\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import os<\/p>\n<h2><strong>\u8bbe\u7f6e\u6587\u4ef6\u6743\u9650\u4e3a0755<\/strong><\/h2>\n<p>file_path = &#39;example.txt&#39;<\/p>\n<p>os.chmod(file_path, 0o755)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u4f7f\u7528<code>os.chmod()<\/code>\u51fd\u6570\u5c06\u6587\u4ef6\u201cexample.txt\u201d\u7684\u6743\u9650\u8bbe\u7f6e\u4e3a0755\u3002<\/p>\n<\/p>\n<p><h4>2. \u5904\u7406\u4e8c\u8fdb\u5236\u6570\u636e<\/h4>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u4f4e\u7ea7\u7f16\u7a0b\u4e2d\uff0c\u516b\u8fdb\u5236\u6570\u7528\u4e8e\u5904\u7406\u4e8c\u8fdb\u5236\u6570\u636e\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528\u516b\u8fdb\u5236\u6570\u8868\u793a\u548c\u64cd\u4f5c\u5b57\u8282\u6570\u636e\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">byte_data = b&#39;\\x53\\x54\\x55&#39;<\/p>\n<p>octal_data = [oct(byte) for byte in byte_data]<\/p>\n<p>print(octal_data)  # \u8f93\u51fa\u7ed3\u679c\u4e3a [&#39;0o123&#39;, &#39;0o124&#39;, &#39;0o125&#39;]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u5c06\u5b57\u8282\u6570\u636e\u8f6c\u6362\u4e3a\u516b\u8fdb\u5236\u5b57\u7b26\u4e32\u8868\u793a\u3002<\/p>\n<\/p>\n<p><h3>\u516b\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u8868\u793a\u516b\u8fdb\u5236\u6570\u6709\u591a\u79cd\u65b9\u6cd5\uff0c\u5305\u62ec\u4f7f\u7528\u524d\u7f00\u201c0o\u201d\u3001\u4f7f\u7528\u5185\u7f6e\u51fd\u6570<code>oct()<\/code>\u4ee5\u53ca\u7f16\u5199\u81ea\u5b9a\u4e49\u51fd\u6570\u8fdb\u884c\u8f6c\u6362\u3002\u516b\u8fdb\u5236\u6570\u5728\u8ba1\u7b97\u673a\u79d1\u5b66\u548c\u6570\u5b57\u7535\u5b50\u5b66\u4e2d\u6709\u5e7f\u6cdb\u7684\u5e94\u7528\uff0c\u4f8b\u5982\u6587\u4ef6\u6743\u9650\u8868\u793a\u3001\u5185\u5b58\u5730\u5740\u8868\u793a\u548c\u6570\u636e\u538b\u7f29\u7b49\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u7406\u89e3\u516b\u8fdb\u5236\u6570\u7684\u8868\u793a\u548c\u8f6c\u6362\u65b9\u6cd5\uff0c\u53ef\u4ee5\u66f4\u597d\u5730\u5904\u7406\u548c\u5e94\u7528\u516b\u8fdb\u5236\u6570\u3002\u540c\u65f6\uff0c\u6ce8\u610f\u5728\u5904\u7406\u516b\u8fdb\u5236\u6570\u65f6\u7684\u6ce8\u610f\u4e8b\u9879\uff0c\u786e\u4fdd\u4ee3\u7801\u7684\u6b63\u786e\u6027\u548c\u7a33\u5b9a\u6027\u3002\u5e0c\u671b\u8fd9\u7bc7\u6587\u7ae0\u80fd\u591f\u5e2e\u52a9\u60a8\u66f4\u597d\u5730\u7406\u89e3\u548c\u4f7f\u7528Python\u4e2d\u7684\u516b\u8fdb\u5236\u6570\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u8868\u793a\u516b\u8fdb\u5236\u6570123\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u516b\u8fdb\u5236\u6570\u53ef\u4ee5\u901a\u8fc7\u5728\u6570\u5b57\u524d\u52a0\u4e0a\u524d\u7f00<code>0o<\/code>\u6216<code>0O<\/code>\u6765\u8868\u793a\u3002\u5bf9\u4e8e\u516b\u8fdb\u5236\u6570123\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528<code>0o123<\/code>\u6765\u8868\u793a\u5b83\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0cPython 3\u4f1a\u5c06\u4ee5<code>0o<\/code>\u5f00\u5934\u7684\u6570\u5b57\u8bc6\u522b\u4e3a\u516b\u8fdb\u5236\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u5982\u4f55\u5c06\u516b\u8fdb\u5236\u6570\u8f6c\u6362\u4e3a\u5341\u8fdb\u5236\uff1f<\/strong><br \/>\u53ef\u4ee5\u4f7f\u7528\u5185\u7f6e\u7684<code>int()<\/code>\u51fd\u6570\u5c06\u516b\u8fdb\u5236\u6570\u8f6c\u6362\u4e3a\u5341\u8fdb\u5236\u3002\u5728<code>int()<\/code>\u51fd\u6570\u4e2d\uff0c\u5c06\u516b\u8fdb\u5236\u6570\u4f5c\u4e3a\u5b57\u7b26\u4e32\u4f20\u5165\uff0c\u5e76\u6307\u5b9a\u57fa\u6570\u4e3a8\u3002\u4f8b\u5982\uff0c<code>int(&#39;123&#39;, 8)<\/code>\u4f1a\u8fd4\u56de\u5341\u8fdb\u5236\u768483\u3002<\/p>\n<p><strong>\u5982\u4f55\u9a8c\u8bc1\u4e00\u4e2a\u6570\u662f\u5426\u4e3a\u516b\u8fdb\u5236\u6570\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u68c0\u67e5\u5b57\u7b26\u4e32\u4e2d\u7684\u6bcf\u4e2a\u5b57\u7b26\u662f\u5426\u5747\u57280\u52307\u4e4b\u95f4\u6765\u9a8c\u8bc1\u4e00\u4e2a\u6570\u662f\u5426\u4e3a\u516b\u8fdb\u5236\u6570\u3002\u53ef\u4ee5\u4f7f\u7528\u5faa\u73af\u6216\u6b63\u5219\u8868\u8fbe\u5f0f\u6765\u5b9e\u73b0\u8fd9\u4e00\u70b9\u3002\u4f8b\u5982\uff0c\u4f7f\u7528<code>all(char in &#39;01234567&#39; for char in str_number)<\/code>\u53ef\u4ee5\u5224\u65ad<code>str_number<\/code>\u662f\u5426\u662f\u516b\u8fdb\u5236\u8868\u793a\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u8868\u793a\u516b\u8fdb\u5236\u6570123\u7684\u65b9\u6cd5\u6709\uff1a\u4f7f\u7528\u524d\u7f00&#39;0o&#39;\u3001\u4f7f\u7528\u5185\u7f6e\u51fd\u6570oct()\u3001\u4f7f\u7528\u81ea\u5b9a\u4e49\u51fd [&hellip;]","protected":false},"author":3,"featured_media":1118004,"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\/1117994"}],"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=1117994"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1117994\/revisions"}],"predecessor-version":[{"id":1118007,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1117994\/revisions\/1118007"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1118004"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1117994"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1117994"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1117994"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}