{"id":970171,"date":"2024-12-27T05:23:39","date_gmt":"2024-12-26T21:23:39","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/970171.html"},"modified":"2024-12-27T05:23:41","modified_gmt":"2024-12-26T21:23:41","slug":"python%e4%b8%ad%e5%a6%82%e4%bd%95%e8%bd%ac%e6%8d%a2%e8%bf%9b%e5%88%b6","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/970171.html","title":{"rendered":"python\u4e2d\u5982\u4f55\u8f6c\u6362\u8fdb\u5236"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24184111\/288de990-217f-40b1-a1cc-2aab59fbf0e7.webp\" alt=\"python\u4e2d\u5982\u4f55\u8f6c\u6362\u8fdb\u5236\" \/><\/p>\n<p><p> \u5728Python\u4e2d\u8f6c\u6362\u8fdb\u5236\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u6cd5\u5b9e\u73b0\uff0c\u5305\u62ec\u5185\u7f6e\u51fd\u6570\u3001\u4f4d\u8fd0\u7b97\u4ee5\u53ca\u81ea\u5b9a\u4e49\u7b97\u6cd5\u7b49\u3002<strong>\u4f7f\u7528\u5185\u7f6e\u51fd\u6570\u3001\u4f4d\u8fd0\u7b97\u548c\u5b57\u7b26\u4e32\u683c\u5f0f\u5316\u662fPython\u4e2d\u5e38\u7528\u7684\u8fdb\u5236\u8f6c\u6362\u65b9\u6cd5<\/strong>\u3002\u5185\u7f6e\u51fd\u6570\u5982<code>bin()<\/code>\u3001<code>oct()<\/code>\u3001<code>hex()<\/code>\u53ef\u4ee5\u8f7b\u677e\u5b9e\u73b0\u4e8c\u8fdb\u5236\u3001\u516b\u8fdb\u5236\u548c\u5341\u516d\u8fdb\u5236\u7684\u8f6c\u6362\uff0c\u800c\u901a\u8fc7\u4f4d\u8fd0\u7b97\u53ef\u4ee5\u5b9e\u73b0\u66f4\u590d\u6742\u7684\u8fdb\u5236\u8f6c\u6362\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u4e9b\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u4f7f\u7528\u5185\u7f6e\u51fd\u6570\u8fdb\u884c\u8fdb\u5236\u8f6c\u6362<\/p>\n<\/p>\n<p><p>Python\u63d0\u4f9b\u4e86\u4e00\u4e9b\u5185\u7f6e\u51fd\u6570\u6765\u65b9\u4fbf\u5730\u8fdb\u884c\u4e0d\u540c\u8fdb\u5236\u4e4b\u95f4\u7684\u8f6c\u6362\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u4e8c\u8fdb\u5236\u8f6c\u6362<\/strong><\/li>\n<\/ol>\n<p><p>Python\u4e2d\u7684<code>bin()<\/code>\u51fd\u6570\u53ef\u4ee5\u5c06\u6574\u6570\u8f6c\u6362\u4e3a\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32\u3002\u4f7f\u7528\u8be5\u51fd\u6570\u65f6\uff0c\u4f20\u5165\u4e00\u4e2a\u6574\u6570\uff0c\u8fd4\u56de\u4e00\u4e2a\u4ee5\u201c0b\u201d\u5f00\u5934\u7684\u5b57\u7b26\u4e32\uff0c\u4ee3\u8868\u8be5\u6574\u6570\u7684\u4e8c\u8fdb\u5236\u5f62\u5f0f\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">num = 10<\/p>\n<p>binary = bin(num)<\/p>\n<p>print(binary)  # \u8f93\u51fa\uff1a0b1010<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u516b\u8fdb\u5236\u8f6c\u6362<\/strong><\/li>\n<\/ol>\n<p><p>\u7c7b\u4f3c\u4e8e<code>bin()<\/code>\uff0c<code>oct()<\/code>\u51fd\u6570\u7528\u4e8e\u5c06\u6574\u6570\u8f6c\u6362\u4e3a\u516b\u8fdb\u5236\u5b57\u7b26\u4e32\uff0c\u8fd4\u56de\u4e00\u4e2a\u4ee5\u201c0o\u201d\u5f00\u5934\u7684\u5b57\u7b26\u4e32\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">num = 10<\/p>\n<p>octal = oct(num)<\/p>\n<p>print(octal)  # \u8f93\u51fa\uff1a0o12<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u5341\u516d\u8fdb\u5236\u8f6c\u6362<\/strong><\/li>\n<\/ol>\n<p><p><code>hex()<\/code>\u51fd\u6570\u7528\u4e8e\u5c06\u6574\u6570\u8f6c\u6362\u4e3a\u5341\u516d\u8fdb\u5236\u5b57\u7b26\u4e32\uff0c\u8fd4\u56de\u4e00\u4e2a\u4ee5\u201c0x\u201d\u5f00\u5934\u7684\u5b57\u7b26\u4e32\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">num = 10<\/p>\n<p>hexadecimal = hex(num)<\/p>\n<p>print(hexadecimal)  # \u8f93\u51fa\uff1a0xa<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e8c\u3001\u4f7f\u7528\u5b57\u7b26\u4e32\u683c\u5f0f\u5316\u8fdb\u884c\u8fdb\u5236\u8f6c\u6362<\/p>\n<\/p>\n<p><p>Python\u7684\u5b57\u7b26\u4e32\u683c\u5f0f\u5316\u529f\u80fd\u4e5f\u53ef\u4ee5\u7528\u4e8e\u8fdb\u5236\u8f6c\u6362\uff0c\u7279\u522b\u662f\u5728\u9700\u8981\u683c\u5f0f\u5316\u8f93\u51fa\u65f6\u975e\u5e38\u6709\u7528\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u683c\u5f0f\u5316\u5b57\u7b26\u4e32<\/strong><\/li>\n<\/ol>\n<p><p>\u4f7f\u7528Python\u7684\u5b57\u7b26\u4e32\u683c\u5f0f\u5316\u65b9\u6cd5\uff0c\u53ef\u4ee5\u8f7b\u677e\u5730\u5c06\u6574\u6570\u8f6c\u6362\u4e3a\u4e0d\u540c\u7684\u8fdb\u5236\u8868\u793a\u3002\u4f8b\u5982\uff0c\u4f7f\u7528\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u7684\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">num = 10<\/p>\n<p>binary = format(num, &#39;b&#39;)  # \u4e8c\u8fdb\u5236<\/p>\n<p>octal = format(num, &#39;o&#39;)   # \u516b\u8fdb\u5236<\/p>\n<p>hexadecimal = format(num, &#39;x&#39;)  # \u5341\u516d\u8fdb\u5236<\/p>\n<p>print(binary)  # \u8f93\u51fa\uff1a1010<\/p>\n<p>print(octal)   # \u8f93\u51fa\uff1a12<\/p>\n<p>print(hexadecimal)  # \u8f93\u51fa\uff1aa<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u5b57\u7b26\u4e32\u63d2\u503c<\/strong><\/li>\n<\/ol>\n<p><p>\u5728Python 3.6\u53ca\u4ee5\u4e0a\u7248\u672c\uff0c\u53ef\u4ee5\u4f7f\u7528f-string\u8fdb\u884c\u63d2\u503c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">num = 10<\/p>\n<p>binary = f&quot;{num:b}&quot;<\/p>\n<p>octal = f&quot;{num:o}&quot;<\/p>\n<p>hexadecimal = f&quot;{num:x}&quot;<\/p>\n<p>print(binary)  # \u8f93\u51fa\uff1a1010<\/p>\n<p>print(octal)   # \u8f93\u51fa\uff1a12<\/p>\n<p>print(hexadecimal)  # \u8f93\u51fa\uff1aa<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e09\u3001\u4f7f\u7528\u81ea\u5b9a\u4e49\u51fd\u6570\u8fdb\u884c\u8fdb\u5236\u8f6c\u6362<\/p>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u5185\u7f6e\u51fd\u6570\u53ef\u80fd\u65e0\u6cd5\u6ee1\u8db3\u7279\u5b9a\u7684\u9700\u6c42\uff0c\u6b64\u65f6\u53ef\u4ee5\u7f16\u5199\u81ea\u5b9a\u4e49\u51fd\u6570\u6765\u5b9e\u73b0\u8fdb\u5236\u8f6c\u6362\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u4efb\u610f\u8fdb\u5236\u8f6c\u6362<\/strong><\/li>\n<\/ol>\n<p><p>\u81ea\u5b9a\u4e49\u51fd\u6570\u53ef\u4ee5\u5b9e\u73b0\u4efb\u610f\u8fdb\u5236\u4e4b\u95f4\u7684\u8f6c\u6362\u3002\u4f8b\u5982\uff0c\u5c06\u5341\u8fdb\u5236\u8f6c\u6362\u4e3a\u4efb\u610f\u8fdb\u5236\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def decimal_to_base(n, base):<\/p>\n<p>    if n &lt; 0:<\/p>\n<p>        return &#39;-&#39; + decimal_to_base(-n, base)<\/p>\n<p>    digits = &quot;0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ&quot;<\/p>\n<p>    if n &lt; base:<\/p>\n<p>        return digits[n]<\/p>\n<p>    else:<\/p>\n<p>        return decimal_to_base(n \/\/ base, base) + digits[n % base]<\/p>\n<p>num = 10<\/p>\n<p>base = 2<\/p>\n<p>converted = decimal_to_base(num, base)<\/p>\n<p>print(converted)  # \u8f93\u51fa\uff1a1010<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u4efb\u610f\u8fdb\u5236\u8f6c\u5341\u8fdb\u5236<\/strong><\/li>\n<\/ol>\n<p><p>\u5c06\u4efb\u610f\u8fdb\u5236\u7684\u6570\u8f6c\u6362\u4e3a\u5341\u8fdb\u5236\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u5b9e\u73b0\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def base_to_decimal(s, base):<\/p>\n<p>    digits = &quot;0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ&quot;<\/p>\n<p>    n = 0<\/p>\n<p>    for char in s:<\/p>\n<p>        n = n * base + digits.index(char)<\/p>\n<p>    return n<\/p>\n<p>s = &quot;1010&quot;<\/p>\n<p>base = 2<\/p>\n<p>num = base_to_decimal(s, base)<\/p>\n<p>print(num)  # \u8f93\u51fa\uff1a10<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u56db\u3001\u4f7f\u7528\u4f4d\u8fd0\u7b97\u8fdb\u884c\u8fdb\u5236\u8f6c\u6362<\/p>\n<\/p>\n<p><p>\u4f4d\u8fd0\u7b97\u662f\u64cd\u4f5c\u6570\u5b57\u7684\u4e8c\u8fdb\u5236\u4f4d\u7684\u4e00\u79cd\u65b9\u6cd5\uff0c\u53ef\u4ee5\u7528\u4e8e\u8fdb\u5236\u8f6c\u6362\uff0c\u7279\u522b\u662f\u5728\u5904\u7406\u5e95\u5c42\u4e8c\u8fdb\u5236\u6570\u636e\u65f6\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u4f4d\u8fd0\u7b97\u57fa\u672c\u539f\u7406<\/strong><\/li>\n<\/ol>\n<p><p>\u4f4d\u8fd0\u7b97\u5305\u62ec\u4e0e\uff08&amp;\uff09\u3001\u6216\uff08|\uff09\u3001\u975e\uff08~\uff09\u3001\u5f02\u6216\uff08^\uff09\u3001\u5de6\u79fb\uff08&lt;&lt;\uff09\u3001\u53f3\u79fb\uff08&gt;&gt;\uff09\u7b49\u64cd\u4f5c\u3002\u901a\u8fc7\u8fd9\u4e9b\u64cd\u4f5c\uff0c\u53ef\u4ee5\u624b\u52a8\u5b9e\u73b0\u8fdb\u5236\u8f6c\u6362\u3002\u4f8b\u5982\uff0c\u901a\u8fc7\u5de6\u79fb\u548c\u53f3\u79fb\u64cd\u4f5c\uff0c\u53ef\u4ee5\u5b9e\u73b0\u4e58\u9664\u6cd5\u8fd0\u7b97\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u901a\u8fc7\u4f4d\u8fd0\u7b97\u5b9e\u73b0\u8fdb\u5236\u8f6c\u6362<\/strong><\/li>\n<\/ol>\n<p><p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u5229\u7528\u4f4d\u8fd0\u7b97\u5b9e\u73b0\u4e8c\u8fdb\u5236\u8f6c\u5341\u8fdb\u5236\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def binary_to_decimal(binary_str):<\/p>\n<p>    result = 0<\/p>\n<p>    for char in binary_str:<\/p>\n<p>        result = (result &lt;&lt; 1) | int(char)<\/p>\n<p>    return result<\/p>\n<p>binary_str = &quot;1010&quot;<\/p>\n<p>decimal = binary_to_decimal(binary_str)<\/p>\n<p>print(decimal)  # \u8f93\u51fa\uff1a10<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e94\u3001\u7ed3\u5408\u5e93\u51fd\u6570\u8fdb\u884c\u9ad8\u7ea7\u8fdb\u5236\u8f6c\u6362<\/p>\n<\/p>\n<p><p>\u5728\u8fdb\u884c\u590d\u6742\u7684\u8fdb\u5236\u8f6c\u6362\u65f6\uff0c\u7ed3\u5408Python\u7684\u5e93\u51fd\u6570\u53ef\u4ee5\u7b80\u5316\u5b9e\u73b0\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u4f7f\u7528<code>int()<\/code>\u548c<code>str()<\/code>\u51fd\u6570<\/strong><\/li>\n<\/ol>\n<p><p><code>int()<\/code>\u51fd\u6570\u4e0d\u4ec5\u53ef\u4ee5\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u6574\u6570\uff0c\u8fd8\u53ef\u4ee5\u7528\u4e8e\u5c06\u4e0d\u540c\u8fdb\u5236\u7684\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u5341\u8fdb\u5236\u6574\u6570\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">binary_str = &quot;1010&quot;<\/p>\n<p>num = int(binary_str, 2)<\/p>\n<p>print(num)  # \u8f93\u51fa\uff1a10<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u4f7f\u7528<code>numpy<\/code>\u8fdb\u884c\u6279\u91cf\u8f6c\u6362<\/strong><\/li>\n<\/ol>\n<p><p>\u5bf9\u4e8e\u9700\u8981\u8fdb\u884c\u5927\u91cf\u8fdb\u5236\u8f6c\u6362\u7684\u573a\u666f\uff0c\u53ef\u4ee5\u4f7f\u7528<code>numpy<\/code>\u5e93\u6765\u63d0\u9ad8\u6548\u7387\u3002\u4f8b\u5982\uff0c\u5c06\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u4ece\u5341\u8fdb\u5236\u8f6c\u6362\u4e3a\u4e8c\u8fdb\u5236\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>arr = np.array([10, 15, 20])<\/p>\n<p>binary_arr = np.vectorize(lambda x: format(x, &#39;b&#39;))(arr)<\/p>\n<p>print(binary_arr)  # \u8f93\u51fa\uff1a[&#39;1010&#39; &#39;1111&#39; &#39;10100&#39;]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u516d\u3001\u8fdb\u5236\u8f6c\u6362\u7684\u5b9e\u9645\u5e94\u7528<\/p>\n<\/p>\n<p><p>\u8fdb\u5236\u8f6c\u6362\u5728\u8ba1\u7b97\u673a\u79d1\u5b66\u4e2d\u6709\u5e7f\u6cdb\u7684\u5e94\u7528\uff0c\u4f8b\u5982\u5728\u7f51\u7edc\u7f16\u7a0b\u4e2d\u5904\u7406IP\u5730\u5740\u548c\u7aef\u53e3\u53f7\u3001\u5728\u5d4c\u5165\u5f0f\u7cfb\u7edf\u4e2d\u5904\u7406\u786c\u4ef6\u5bc4\u5b58\u5668\u3001\u4ee5\u53ca\u5728\u6570\u636e\u52a0\u5bc6\u548c\u89e3\u5bc6\u4e2d\u5904\u7406\u5bc6\u94a5\u548c\u660e\u6587\u7b49\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>IP\u5730\u5740\u5904\u7406<\/strong><\/li>\n<\/ol>\n<p><p>\u5728\u7f51\u7edc\u7f16\u7a0b\u4e2d\uff0c\u7ecf\u5e38\u9700\u8981\u5c06IP\u5730\u5740\u4ece\u70b9\u5206\u5341\u8fdb\u5236\u683c\u5f0f\u8f6c\u6362\u4e3a\u4e8c\u8fdb\u5236\u683c\u5f0f\uff0c\u4ee5\u4fbf\u8fdb\u884c\u4f4d\u64cd\u4f5c\u548c\u63a9\u7801\u8ba1\u7b97\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u6570\u636e\u52a0\u5bc6<\/strong><\/li>\n<\/ol>\n<p><p>\u5728\u6570\u636e\u52a0\u5bc6\u548c\u89e3\u5bc6\u4e2d\uff0c\u901a\u5e38\u9700\u8981\u5c06\u6570\u636e\u4ece\u4e00\u79cd\u8fdb\u5236\u683c\u5f0f\u8f6c\u6362\u4e3a\u53e6\u4e00\u79cd\u8fdb\u5236\u683c\u5f0f\uff0c\u4ee5\u4fbf\u8fdb\u884c\u52a0\u5bc6\u7b97\u6cd5\u7684\u5904\u7406\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u65b9\u6cd5\u548c\u5e94\u7528\u793a\u4f8b\uff0c\u53ef\u4ee5\u5168\u9762\u638c\u63e1Python\u4e2d\u8fdb\u5236\u8f6c\u6362\u7684\u591a\u79cd\u5b9e\u73b0\u65b9\u5f0f\uff0c\u5e76\u80fd\u591f\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\u7075\u6d3b\u5e94\u7528\u8fd9\u4e9b\u6280\u672f\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5728Python\u4e2d\u5982\u4f55\u5c06\u5341\u8fdb\u5236\u6570\u8f6c\u6362\u4e3a\u4e8c\u8fdb\u5236\u3001\u516b\u8fdb\u5236\u6216\u5341\u516d\u8fdb\u5236\uff1f<\/strong><br \/>Python\u63d0\u4f9b\u4e86\u5185\u7f6e\u7684\u51fd\u6570\u6765\u5b9e\u73b0\u8fdb\u5236\u8f6c\u6362\u3002\u4f7f\u7528<code>bin()<\/code>\u51fd\u6570\u53ef\u4ee5\u5c06\u5341\u8fdb\u5236\u6570\u8f6c\u6362\u4e3a\u4e8c\u8fdb\u5236\uff0c\u8fd4\u56de\u503c\u4ee5&#39;0b&#39;\u5f00\u5934\uff1b\u4f7f\u7528<code>oct()<\/code>\u51fd\u6570\u5c06\u5176\u8f6c\u6362\u4e3a\u516b\u8fdb\u5236\uff0c\u8fd4\u56de\u503c\u4ee5&#39;0o&#39;\u5f00\u5934\uff1b\u4f7f\u7528<code>hex()<\/code>\u51fd\u6570\u5219\u53ef\u4ee5\u5f97\u5230\u5341\u516d\u8fdb\u5236\u8868\u793a\uff0c\u8fd4\u56de\u503c\u4ee5&#39;0x&#39;\u5f00\u5934\u3002\u4f8b\u5982\uff0c<code>bin(10)<\/code>\u4f1a\u8fd4\u56de&#39;0b1010&#39;\uff0c<code>oct(10)<\/code>\u8fd4\u56de&#39;0o12&#39;\uff0c\u800c<code>hex(10)<\/code>\u8fd4\u56de&#39;0xa&#39;\u3002<\/p>\n<p><strong>\u5982\u4f55\u5c06\u5b57\u7b26\u4e32\u683c\u5f0f\u7684\u6570\u5b57\u8f6c\u6362\u4e3a\u4e0d\u540c\u8fdb\u5236\uff1f<\/strong><br \/>\u5982\u679c\u4f60\u6709\u4e00\u4e2a\u5b57\u7b26\u4e32\u683c\u5f0f\u7684\u6570\u5b57\uff0c\u6bd4\u5982&#39;10&#39;\uff0c\u5e76\u5e0c\u671b\u5c06\u5176\u8f6c\u6362\u4e3a\u5176\u4ed6\u8fdb\u5236\uff0c\u9996\u5148\u9700\u8981\u4f7f\u7528<code>int()<\/code>\u51fd\u6570\u5c06\u5176\u8f6c\u6362\u4e3a\u6574\u6570\u3002\u7136\u540e\uff0c\u4f9d\u7136\u53ef\u4ee5\u4f7f\u7528<code>bin()<\/code>\u3001<code>oct()<\/code>\u548c<code>hex()<\/code>\u8fdb\u884c\u8f6c\u6362\u3002\u4f8b\u5982\uff0c<code>int(&#39;10&#39;)<\/code>\u53ef\u4ee5\u5f97\u5230\u6574\u657010\uff0c\u63a5\u7740\u4f7f\u7528<code>bin(int(&#39;10&#39;))<\/code>\u53ef\u4ee5\u5f97\u5230&#39;0b1010&#39;\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u5982\u4f55\u8fdb\u884c\u81ea\u5b9a\u4e49\u8fdb\u5236\u7684\u8f6c\u6362\uff1f<\/strong><br \/>\u5728\u9700\u8981\u8f6c\u6362\u4e3a\u975e\u6807\u51c6\u8fdb\u5236\uff08\u4f8b\u59823\u8fdb\u5236\u62167\u8fdb\u5236\uff09\u65f6\uff0c\u53ef\u4ee5\u7f16\u5199\u81ea\u5b9a\u4e49\u51fd\u6570\u3002\u53ef\u4ee5\u901a\u8fc7\u4e0d\u65ad\u9664\u4ee5\u76ee\u6807\u8fdb\u5236\u5e76\u8bb0\u5f55\u4f59\u6570\u6765\u5b9e\u73b0\u3002\u5728\u6bcf\u4e00\u6b65\u4e2d\uff0c\u5c06\u4f59\u6570\u52a0\u5165\u5230\u7ed3\u679c\u4e2d\uff0c\u76f4\u5230\u5546\u4e3a0\u3002\u6700\u7ec8\uff0c\u53cd\u8f6c\u4f59\u6570\u5217\u8868\u4ee5\u83b7\u5f97\u6b63\u786e\u7684\u8fdb\u5236\u8868\u793a\u3002\u8fd9\u6837\u7684\u51fd\u6570\u53ef\u4ee5\u7075\u6d3b\u5904\u7406\u4efb\u610f\u8fdb\u5236\u7684\u8f6c\u6362\u9700\u6c42\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u8f6c\u6362\u8fdb\u5236\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u6cd5\u5b9e\u73b0\uff0c\u5305\u62ec\u5185\u7f6e\u51fd\u6570\u3001\u4f4d\u8fd0\u7b97\u4ee5\u53ca\u81ea\u5b9a\u4e49\u7b97\u6cd5\u7b49\u3002\u4f7f\u7528\u5185\u7f6e\u51fd\u6570\u3001\u4f4d\u8fd0\u7b97\u548c\u5b57\u7b26 [&hellip;]","protected":false},"author":3,"featured_media":970178,"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\/970171"}],"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=970171"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/970171\/revisions"}],"predecessor-version":[{"id":970179,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/970171\/revisions\/970179"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/970178"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=970171"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=970171"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=970171"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}