{"id":223,"date":"2017-01-10T11:27:44","date_gmt":"2017-01-10T03:27:44","guid":{"rendered":"http:\/\/luchanglong.com.cn\/?p=223"},"modified":"2017-01-17T14:36:49","modified_gmt":"2017-01-17T06:36:49","slug":"python-%e5%ad%97%e7%ac%a6%e4%b8%b2%e5%92%8c%e7%bc%96%e7%a0%81","status":"publish","type":"post","link":"https:\/\/blog.la998.com\/?p=223","title":{"rendered":"python \u5b57\u7b26\u4e32\u548c\u7f16\u7801"},"content":{"rendered":"<p>Python\u63d0\u4f9b\u4e86<code>ord()<\/code>\u51fd\u6570\u83b7\u53d6\u5b57\u7b26\u7684\u6574\u6570\u8868\u793a\uff0c<code>chr()<\/code>\u51fd\u6570\u628a\u7f16\u7801\u8f6c\u6362\u4e3a\u5bf9\u5e94\u7684\u5b57\u7b26\u3002<\/p>\n<pre class=\"lang:python decode:true\">&gt;&gt;&gt; ord('A')\r\n65\r\n&gt;&gt;&gt; ord('\u4e2d')\r\n20013\r\n&gt;&gt;&gt; chr(66)\r\n'B'\r\n&gt;&gt;&gt; chr(25991)\r\n'\u6587'<\/pre>\n<p>\u5982\u679c\u77e5\u9053\u5b57\u7b26\u7684\u6574\u6570\u7f16\u7801\uff0c\u8fd8\u53ef\u4ee5\u7528\u5341\u516d\u8fdb\u5236\u8fd9\u4e48\u5199<code>str<\/code><\/p>\n<pre class=\"lang:python decode:true \">&gt;&gt;&gt; '\\u4e2d\\u6587'\r\n'\u4e2d\u6587'<\/pre>\n<p>\u7531\u4e8ePython\u7684\u5b57\u7b26\u4e32\u7c7b\u578b\u662f<code>str<\/code>\uff0c\u5728\u5185\u5b58\u4e2d\u4ee5Unicode\u8868\u793a\uff0c\u4e00\u4e2a\u5b57\u7b26\u5bf9\u5e94\u82e5\u5e72\u4e2a\u5b57\u8282\u3002\u5982\u679c\u8981\u5728\u7f51\u7edc\u4e0a\u4f20\u8f93\uff0c\u6216\u8005\u4fdd\u5b58\u5230\u78c1\u76d8\u4e0a\uff0c\u5c31\u9700\u8981\u628a<code>str<\/code>\u53d8\u4e3a\u4ee5\u5b57\u8282\u4e3a\u5355\u4f4d\u7684<code>bytes<\/code>\u3002<\/p>\n<p>Python\u5bf9<code>bytes<\/code>\u7c7b\u578b\u7684\u6570\u636e\u7528\u5e26<code>b<\/code>\u524d\u7f00\u7684\u5355\u5f15\u53f7\u6216\u53cc\u5f15\u53f7\u8868\u793a\uff1a<\/p>\n<pre><code class=\"ini\"><span class=\"setting\">x = <span class=\"value\">b'ABC'<\/span><\/span>\r\n<\/code><\/pre>\n<p>\u8981\u6ce8\u610f\u533a\u5206<code>'ABC'<\/code>\u548c<code>b'ABC'<\/code>\uff0c\u524d\u8005\u662f<code>str<\/code>\uff0c\u540e\u8005\u867d\u7136\u5185\u5bb9\u663e\u793a\u5f97\u548c\u524d\u8005\u4e00\u6837\uff0c\u4f46<code>bytes<\/code>\u7684\u6bcf\u4e2a\u5b57\u7b26\u90fd\u53ea\u5360\u7528\u4e00\u4e2a\u5b57\u8282\u3002<\/p>\n<p>\u4ee5Unicode\u8868\u793a\u7684<code>str<\/code>\u901a\u8fc7<code>encode()<\/code>\u65b9\u6cd5\u53ef\u4ee5\u7f16\u7801\u4e3a\u6307\u5b9a\u7684<code>bytes<\/code>\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre><code class=\"xml\">&gt;&gt;&gt; 'ABC'.encode('ascii')\r\nb'ABC'\r\n&gt;&gt;&gt; '\u4e2d\u6587'.encode('utf-8')\r\nb'\\xe4\\xb8\\xad\\xe6\\x96\\x87'\r\n&gt;&gt;&gt; '\u4e2d\u6587'.encode('ascii')\r\nTraceback (most recent call last):\r\n  File \"<span class=\"tag\">&lt;<span class=\"title\">stdin<\/span>&gt;<\/span>\", line 1, in <span class=\"tag\">&lt;<span class=\"title\">module<\/span>&gt;<\/span>\r\nUnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)\r\n<\/code><\/pre>\n<p>\u7eaf\u82f1\u6587\u7684<code>str<\/code>\u53ef\u4ee5\u7528<code>ASCII<\/code>\u7f16\u7801\u4e3a<code>bytes<\/code>\uff0c\u5185\u5bb9\u662f\u4e00\u6837\u7684\uff0c\u542b\u6709\u4e2d\u6587\u7684<code>str<\/code>\u53ef\u4ee5\u7528<code>UTF-8<\/code>\u7f16\u7801\u4e3a<code>bytes<\/code>\u3002\u542b\u6709\u4e2d\u6587\u7684<code>str<\/code>\u65e0\u6cd5\u7528<code>ASCII<\/code>\u7f16\u7801\uff0c\u56e0\u4e3a\u4e2d\u6587\u7f16\u7801\u7684\u8303\u56f4\u8d85\u8fc7\u4e86<code>ASCII<\/code>\u7f16\u7801\u7684\u8303\u56f4\uff0cPython\u4f1a\u62a5\u9519\u3002<\/p>\n<p>\u5728<code>bytes<\/code>\u4e2d\uff0c\u65e0\u6cd5\u663e\u793a\u4e3aASCII\u5b57\u7b26\u7684\u5b57\u8282\uff0c\u7528<code>\\x##<\/code>\u663e\u793a\u3002<\/p>\n<p>\u53cd\u8fc7\u6765\uff0c\u5982\u679c\u6211\u4eec\u4ece\u7f51\u7edc\u6216\u78c1\u76d8\u4e0a\u8bfb\u53d6\u4e86\u5b57\u8282\u6d41\uff0c\u90a3\u4e48\u8bfb\u5230\u7684\u6570\u636e\u5c31\u662f<code>bytes<\/code>\u3002\u8981\u628a<code>bytes<\/code>\u53d8\u4e3a<code>str<\/code>\uff0c\u5c31\u9700\u8981\u7528<code>decode()<\/code>\u65b9\u6cd5\uff1a<\/p>\n<pre><code class=\"python\"><span class=\"prompt\">&gt;&gt;&gt; <\/span><span class=\"string\">b'ABC'<\/span>.decode(<span class=\"string\">'ascii'<\/span>)\r\n<span class=\"string\">'ABC'<\/span>\r\n<span class=\"prompt\">&gt;&gt;&gt; <\/span><span class=\"string\">b'\\xe4\\xb8\\xad\\xe6\\x96\\x87'<\/span>.decode(<span class=\"string\">'utf-8'<\/span>)\r\n<span class=\"string\">'\u4e2d\u6587'<\/span>\r\n<\/code><\/pre>\n<p>\u8981\u8ba1\u7b97<code>str<\/code>\u5305\u542b\u591a\u5c11\u4e2a\u5b57\u7b26\uff0c\u53ef\u4ee5\u7528<code>len()<\/code>\u51fd\u6570\uff1a<\/p>\n<pre><code class=\"python\"><span class=\"prompt\">&gt;&gt;&gt; <\/span>len(<span class=\"string\">'ABC'<\/span>)\r\n<span class=\"number\">3<\/span>\r\n<span class=\"prompt\">&gt;&gt;&gt; <\/span>len(<span class=\"string\">'\u4e2d\u6587'<\/span>)\r\n<span class=\"number\">2<\/span>\r\n<\/code><\/pre>\n<p><code>len()<\/code>\u51fd\u6570\u8ba1\u7b97\u7684\u662f<code>str<\/code>\u7684\u5b57\u7b26\u6570\uff0c\u5982\u679c\u6362\u6210<code>bytes<\/code>\uff0c<code>len()<\/code>\u51fd\u6570\u5c31\u8ba1\u7b97\u5b57\u8282\u6570\uff1a<\/p>\n<pre><code class=\"python\"><span class=\"prompt\">&gt;&gt;&gt; <\/span>len(<span class=\"string\">b'ABC'<\/span>)\r\n<span class=\"number\">3<\/span>\r\n<span class=\"prompt\">&gt;&gt;&gt; <\/span>len(<span class=\"string\">b'\\xe4\\xb8\\xad\\xe6\\x96\\x87'<\/span>)\r\n<span class=\"number\">6<\/span>\r\n<span class=\"prompt\">&gt;&gt;&gt; <\/span>len(<span class=\"string\">'\u4e2d\u6587'<\/span>.encode(<span class=\"string\">'utf-8'<\/span>))\r\n<span class=\"number\">6<\/span>\r\n<\/code><\/pre>\n<p>\u53ef\u89c1\uff0c1\u4e2a\u4e2d\u6587\u5b57\u7b26\u7ecf\u8fc7UTF-8\u7f16\u7801\u540e\u901a\u5e38\u4f1a\u5360\u75283\u4e2a\u5b57\u8282\uff0c\u800c1\u4e2a\u82f1\u6587\u5b57\u7b26\u53ea\u5360\u75281\u4e2a\u5b57\u8282\u3002<\/p>\n<p>\u5728\u64cd\u4f5c\u5b57\u7b26\u4e32\u65f6\uff0c\u6211\u4eec\u7ecf\u5e38\u9047\u5230<code>str<\/code>\u548c<code>bytes<\/code>\u7684\u4e92\u76f8\u8f6c\u6362\u3002\u4e3a\u4e86\u907f\u514d\u4e71\u7801\u95ee\u9898\uff0c\u5e94\u5f53\u59cb\u7ec8\u575a\u6301\u4f7f\u7528UTF-8\u7f16\u7801\u5bf9<code>str<\/code>\u548c<code>bytes<\/code>\u8fdb\u884c\u8f6c\u6362\u3002<\/p>\n<h4>\u5b57\u7b26\u4e32\u548c\u7f16\u7801<\/h4>\n<div class=\"x-wiki-info\">\u9605\u8bfb: 550988<\/div>\n<hr \/>\n<div class=\"x-wiki-content\">\n<h3 id=\"-\">\u5b57\u7b26\u7f16\u7801<\/h3>\n<p>\u6211\u4eec\u5df2\u7ecf\u8bb2\u8fc7\u4e86\uff0c\u5b57\u7b26\u4e32\u4e5f\u662f\u4e00\u79cd\u6570\u636e\u7c7b\u578b\uff0c\u4f46\u662f\uff0c\u5b57\u7b26\u4e32\u6bd4\u8f83\u7279\u6b8a\u7684\u662f\u8fd8\u6709\u4e00\u4e2a\u7f16\u7801\u95ee\u9898\u3002<\/p>\n<p>\u56e0\u4e3a\u8ba1\u7b97\u673a\u53ea\u80fd\u5904\u7406\u6570\u5b57\uff0c\u5982\u679c\u8981\u5904\u7406\u6587\u672c\uff0c\u5c31\u5fc5\u987b\u5148\u628a\u6587\u672c\u8f6c\u6362\u4e3a\u6570\u5b57\u624d\u80fd\u5904\u7406\u3002\u6700\u65e9\u7684\u8ba1\u7b97\u673a\u5728\u8bbe\u8ba1\u65f6\u91c7\u75288\u4e2a\u6bd4\u7279\uff08bit\uff09\u4f5c\u4e3a\u4e00\u4e2a\u5b57\u8282\uff08byte\uff09\uff0c\u6240\u4ee5\uff0c\u4e00\u4e2a\u5b57\u8282\u80fd\u8868\u793a\u7684\u6700\u5927\u7684\u6574\u6570\u5c31\u662f255\uff08\u4e8c\u8fdb\u523611111111=\u5341\u8fdb\u5236255\uff09\uff0c\u5982\u679c\u8981\u8868\u793a\u66f4\u5927\u7684\u6574\u6570\uff0c\u5c31\u5fc5\u987b\u7528\u66f4\u591a\u7684\u5b57\u8282\u3002\u6bd4\u5982\u4e24\u4e2a\u5b57\u8282\u53ef\u4ee5\u8868\u793a\u7684\u6700\u5927\u6574\u6570\u662f<code>65535<\/code>\uff0c4\u4e2a\u5b57\u8282\u53ef\u4ee5\u8868\u793a\u7684\u6700\u5927\u6574\u6570\u662f<code>4294967295<\/code>\u3002<\/p>\n<p>\u7531\u4e8e\u8ba1\u7b97\u673a\u662f\u7f8e\u56fd\u4eba\u53d1\u660e\u7684\uff0c\u56e0\u6b64\uff0c\u6700\u65e9\u53ea\u6709127\u4e2a\u5b57\u6bcd\u88ab\u7f16\u7801\u5230\u8ba1\u7b97\u673a\u91cc\uff0c\u4e5f\u5c31\u662f\u5927\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3001\u6570\u5b57\u548c\u4e00\u4e9b\u7b26\u53f7\uff0c\u8fd9\u4e2a\u7f16\u7801\u8868\u88ab\u79f0\u4e3a<code>ASCII<\/code>\u7f16\u7801\uff0c\u6bd4\u5982\u5927\u5199\u5b57\u6bcd<code>A<\/code>\u7684\u7f16\u7801\u662f<code>65<\/code>\uff0c\u5c0f\u5199\u5b57\u6bcd<code>z<\/code>\u7684\u7f16\u7801\u662f<code>122<\/code>\u3002<\/p>\n<p>\u4f46\u662f\u8981\u5904\u7406\u4e2d\u6587\u663e\u7136\u4e00\u4e2a\u5b57\u8282\u662f\u4e0d\u591f\u7684\uff0c\u81f3\u5c11\u9700\u8981\u4e24\u4e2a\u5b57\u8282\uff0c\u800c\u4e14\u8fd8\u4e0d\u80fd\u548cASCII\u7f16\u7801\u51b2\u7a81\uff0c\u6240\u4ee5\uff0c\u4e2d\u56fd\u5236\u5b9a\u4e86<code>GB2312<\/code>\u7f16\u7801\uff0c\u7528\u6765\u628a\u4e2d\u6587\u7f16\u8fdb\u53bb\u3002<\/p>\n<p>\u4f60\u53ef\u4ee5\u60f3\u5f97\u5230\u7684\u662f\uff0c\u5168\u4e16\u754c\u6709\u4e0a\u767e\u79cd\u8bed\u8a00\uff0c\u65e5\u672c\u628a\u65e5\u6587\u7f16\u5230<code>Shift_JIS<\/code>\u91cc\uff0c\u97e9\u56fd\u628a\u97e9\u6587\u7f16\u5230<code>Euc-kr<\/code>\u91cc\uff0c\u5404\u56fd\u6709\u5404\u56fd\u7684\u6807\u51c6\uff0c\u5c31\u4f1a\u4e0d\u53ef\u907f\u514d\u5730\u51fa\u73b0\u51b2\u7a81\uff0c\u7ed3\u679c\u5c31\u662f\uff0c\u5728\u591a\u8bed\u8a00\u6df7\u5408\u7684\u6587\u672c\u4e2d\uff0c\u663e\u793a\u51fa\u6765\u4f1a\u6709\u4e71\u7801\u3002<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.liaoxuefeng.com\/files\/attachments\/0013872491802084161ec9ef7d143a897e1584819535656000\/0\" alt=\"char-encoding-problem\" \/><\/p>\n<p>\u56e0\u6b64\uff0cUnicode\u5e94\u8fd0\u800c\u751f\u3002Unicode\u628a\u6240\u6709\u8bed\u8a00\u90fd\u7edf\u4e00\u5230\u4e00\u5957\u7f16\u7801\u91cc\uff0c\u8fd9\u6837\u5c31\u4e0d\u4f1a\u518d\u6709\u4e71\u7801\u95ee\u9898\u4e86\u3002<\/p>\n<p>Unicode\u6807\u51c6\u4e5f\u5728\u4e0d\u65ad\u53d1\u5c55\uff0c\u4f46\u6700\u5e38\u7528\u7684\u662f\u7528\u4e24\u4e2a\u5b57\u8282\u8868\u793a\u4e00\u4e2a\u5b57\u7b26\uff08\u5982\u679c\u8981\u7528\u5230\u975e\u5e38\u504f\u50fb\u7684\u5b57\u7b26\uff0c\u5c31\u9700\u89814\u4e2a\u5b57\u8282\uff09\u3002\u73b0\u4ee3\u64cd\u4f5c\u7cfb\u7edf\u548c\u5927\u591a\u6570\u7f16\u7a0b\u8bed\u8a00\u90fd\u76f4\u63a5\u652f\u6301Unicode\u3002<\/p>\n<p>\u73b0\u5728\uff0c\u634b\u4e00\u634bASCII\u7f16\u7801\u548cUnicode\u7f16\u7801\u7684\u533a\u522b\uff1aASCII\u7f16\u7801\u662f1\u4e2a\u5b57\u8282\uff0c\u800cUnicode\u7f16\u7801\u901a\u5e38\u662f2\u4e2a\u5b57\u8282\u3002<\/p>\n<p>\u5b57\u6bcd<code>A<\/code>\u7528ASCII\u7f16\u7801\u662f\u5341\u8fdb\u5236\u7684<code>65<\/code>\uff0c\u4e8c\u8fdb\u5236\u7684<code>01000001<\/code>\uff1b<\/p>\n<p>\u5b57\u7b26<code>0<\/code>\u7528ASCII\u7f16\u7801\u662f\u5341\u8fdb\u5236\u7684<code>48<\/code>\uff0c\u4e8c\u8fdb\u5236\u7684<code>00110000<\/code>\uff0c\u6ce8\u610f\u5b57\u7b26<code>'0'<\/code>\u548c\u6574\u6570<code>0<\/code>\u662f\u4e0d\u540c\u7684\uff1b<\/p>\n<p>\u6c49\u5b57<code>\u4e2d<\/code>\u5df2\u7ecf\u8d85\u51fa\u4e86ASCII\u7f16\u7801\u7684\u8303\u56f4\uff0c\u7528Unicode\u7f16\u7801\u662f\u5341\u8fdb\u5236\u7684<code>20013<\/code>\uff0c\u4e8c\u8fdb\u5236\u7684<code>01001110 00101101<\/code>\u3002<\/p>\n<p>\u4f60\u53ef\u4ee5\u731c\u6d4b\uff0c\u5982\u679c\u628aASCII\u7f16\u7801\u7684<code>A<\/code>\u7528Unicode\u7f16\u7801\uff0c\u53ea\u9700\u8981\u5728\u524d\u9762\u88650\u5c31\u53ef\u4ee5\uff0c\u56e0\u6b64\uff0c<code>A<\/code>\u7684Unicode\u7f16\u7801\u662f<code>00000000 01000001<\/code>\u3002<\/p>\n<p>\u65b0\u7684\u95ee\u9898\u53c8\u51fa\u73b0\u4e86\uff1a\u5982\u679c\u7edf\u4e00\u6210Unicode\u7f16\u7801\uff0c\u4e71\u7801\u95ee\u9898\u4ece\u6b64\u6d88\u5931\u4e86\u3002\u4f46\u662f\uff0c\u5982\u679c\u4f60\u5199\u7684\u6587\u672c\u57fa\u672c\u4e0a\u5168\u90e8\u662f\u82f1\u6587\u7684\u8bdd\uff0c\u7528Unicode\u7f16\u7801\u6bd4ASCII\u7f16\u7801\u9700\u8981\u591a\u4e00\u500d\u7684\u5b58\u50a8\u7a7a\u95f4\uff0c\u5728\u5b58\u50a8\u548c\u4f20\u8f93\u4e0a\u5c31\u5341\u5206\u4e0d\u5212\u7b97\u3002<\/p>\n<p>\u6240\u4ee5\uff0c\u672c\u7740\u8282\u7ea6\u7684\u7cbe\u795e\uff0c\u53c8\u51fa\u73b0\u4e86\u628aUnicode\u7f16\u7801\u8f6c\u5316\u4e3a\u201c\u53ef\u53d8\u957f\u7f16\u7801\u201d\u7684<code>UTF-8<\/code>\u7f16\u7801\u3002UTF-8\u7f16\u7801\u628a\u4e00\u4e2aUnicode\u5b57\u7b26\u6839\u636e\u4e0d\u540c\u7684\u6570\u5b57\u5927\u5c0f\u7f16\u7801\u62101-6\u4e2a\u5b57\u8282\uff0c\u5e38\u7528\u7684\u82f1\u6587\u5b57\u6bcd\u88ab\u7f16\u7801\u62101\u4e2a\u5b57\u8282\uff0c\u6c49\u5b57\u901a\u5e38\u662f3\u4e2a\u5b57\u8282\uff0c\u53ea\u6709\u5f88\u751f\u50fb\u7684\u5b57\u7b26\u624d\u4f1a\u88ab\u7f16\u7801\u62104-6\u4e2a\u5b57\u8282\u3002\u5982\u679c\u4f60\u8981\u4f20\u8f93\u7684\u6587\u672c\u5305\u542b\u5927\u91cf\u82f1\u6587\u5b57\u7b26\uff0c\u7528UTF-8\u7f16\u7801\u5c31\u80fd\u8282\u7701\u7a7a\u95f4\uff1a<\/p>\n<table class=\"uk-table\">\n<tbody>\n<tr>\n<th>\u5b57\u7b26<\/th>\n<th>ASCII<\/th>\n<th>Unicode<\/th>\n<th>UTF-8<\/th>\n<\/tr>\n<tr>\n<td>A<\/td>\n<td>01000001<\/td>\n<td>00000000 01000001<\/td>\n<td>01000001<\/td>\n<\/tr>\n<tr>\n<td>\u4e2d<\/td>\n<td>x<\/td>\n<td>01001110 00101101<\/td>\n<td>11100100 10111000 10101101<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u4ece\u4e0a\u9762\u7684\u8868\u683c\u8fd8\u53ef\u4ee5\u53d1\u73b0\uff0cUTF-8\u7f16\u7801\u6709\u4e00\u4e2a\u989d\u5916\u7684\u597d\u5904\uff0c\u5c31\u662fASCII\u7f16\u7801\u5b9e\u9645\u4e0a\u53ef\u4ee5\u88ab\u770b\u6210\u662fUTF-8\u7f16\u7801\u7684\u4e00\u90e8\u5206\uff0c\u6240\u4ee5\uff0c\u5927\u91cf\u53ea\u652f\u6301ASCII\u7f16\u7801\u7684\u5386\u53f2\u9057\u7559\u8f6f\u4ef6\u53ef\u4ee5\u5728UTF-8\u7f16\u7801\u4e0b\u7ee7\u7eed\u5de5\u4f5c\u3002<\/p>\n<p>\u641e\u6e05\u695a\u4e86ASCII\u3001Unicode\u548cUTF-8\u7684\u5173\u7cfb\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u603b\u7ed3\u4e00\u4e0b\u73b0\u5728\u8ba1\u7b97\u673a\u7cfb\u7edf\u901a\u7528\u7684\u5b57\u7b26\u7f16\u7801\u5de5\u4f5c\u65b9\u5f0f\uff1a<\/p>\n<p>\u5728\u8ba1\u7b97\u673a\u5185\u5b58\u4e2d\uff0c\u7edf\u4e00\u4f7f\u7528Unicode\u7f16\u7801\uff0c\u5f53\u9700\u8981\u4fdd\u5b58\u5230\u786c\u76d8\u6216\u8005\u9700\u8981\u4f20\u8f93\u7684\u65f6\u5019\uff0c\u5c31\u8f6c\u6362\u4e3aUTF-8\u7f16\u7801\u3002<\/p>\n<p>\u7528\u8bb0\u4e8b\u672c\u7f16\u8f91\u7684\u65f6\u5019\uff0c\u4ece\u6587\u4ef6\u8bfb\u53d6\u7684UTF-8\u5b57\u7b26\u88ab\u8f6c\u6362\u4e3aUnicode\u5b57\u7b26\u5230\u5185\u5b58\u91cc\uff0c\u7f16\u8f91\u5b8c\u6210\u540e\uff0c\u4fdd\u5b58\u7684\u65f6\u5019\u518d\u628aUnicode\u8f6c\u6362\u4e3aUTF-8\u4fdd\u5b58\u5230\u6587\u4ef6\uff1a<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.liaoxuefeng.com\/files\/attachments\/001387245992536e2ba28125cf04f5c8985dbc94a02245e000\/0\" alt=\"rw-file-utf-8\" \/><\/p>\n<p>\u6d4f\u89c8\u7f51\u9875\u7684\u65f6\u5019\uff0c\u670d\u52a1\u5668\u4f1a\u628a\u52a8\u6001\u751f\u6210\u7684Unicode\u5185\u5bb9\u8f6c\u6362\u4e3aUTF-8\u518d\u4f20\u8f93\u5230\u6d4f\u89c8\u5668\uff1a<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.liaoxuefeng.com\/files\/attachments\/001387245979827634fd6204f9346a1ae6358d9ed051666000\/0\" alt=\"web-utf-8\" \/><\/p>\n<p>\u6240\u4ee5\u4f60\u770b\u5230\u5f88\u591a\u7f51\u9875\u7684\u6e90\u7801\u4e0a\u4f1a\u6709\u7c7b\u4f3c<code>&lt;meta charset=\"UTF-8\" \/&gt;<\/code>\u7684\u4fe1\u606f\uff0c\u8868\u793a\u8be5\u7f51\u9875\u6b63\u662f\u7528\u7684UTF-8\u7f16\u7801\u3002<\/p>\n<h3 id=\"python-\">Python\u7684\u5b57\u7b26\u4e32<\/h3>\n<p>\u641e\u6e05\u695a\u4e86\u4ee4\u4eba\u5934\u75bc\u7684\u5b57\u7b26\u7f16\u7801\u95ee\u9898\u540e\uff0c\u6211\u4eec\u518d\u6765\u7814\u7a76Python\u7684\u5b57\u7b26\u4e32\u3002<\/p>\n<p>\u5728\u6700\u65b0\u7684Python 3\u7248\u672c\u4e2d\uff0c\u5b57\u7b26\u4e32\u662f\u4ee5Unicode\u7f16\u7801\u7684\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0cPython\u7684\u5b57\u7b26\u4e32\u652f\u6301\u591a\u8bed\u8a00\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre><code class=\"python\"><span class=\"prompt\">&gt;&gt;&gt; <\/span>print(<span class=\"string\">'\u5305\u542b\u4e2d\u6587\u7684str'<\/span>)\r\n\u5305\u542b\u4e2d\u6587\u7684str\r\n<\/code><\/pre>\n<p>\u5bf9\u4e8e\u5355\u4e2a\u5b57\u7b26\u7684\u7f16\u7801\uff0cPython\u63d0\u4f9b\u4e86<code>ord()<\/code>\u51fd\u6570\u83b7\u53d6\u5b57\u7b26\u7684\u6574\u6570\u8868\u793a\uff0c<code>chr()<\/code>\u51fd\u6570\u628a\u7f16\u7801\u8f6c\u6362\u4e3a\u5bf9\u5e94\u7684\u5b57\u7b26\uff1a<\/p>\n<pre><code class=\"python\"><span class=\"prompt\">&gt;&gt;&gt; <\/span>ord(<span class=\"string\">'A'<\/span>)\r\n<span class=\"number\">65<\/span>\r\n<span class=\"prompt\">&gt;&gt;&gt; <\/span>ord(<span class=\"string\">'\u4e2d'<\/span>)\r\n<span class=\"number\">20013<\/span>\r\n<span class=\"prompt\">&gt;&gt;&gt; <\/span>chr(<span class=\"number\">66<\/span>)\r\n<span class=\"string\">'B'<\/span>\r\n<span class=\"prompt\">&gt;&gt;&gt; <\/span>chr(<span class=\"number\">25991<\/span>)\r\n<span class=\"string\">'\u6587'<\/span>\r\n<\/code><\/pre>\n<p>\u5982\u679c\u77e5\u9053\u5b57\u7b26\u7684\u6574\u6570\u7f16\u7801\uff0c\u8fd8\u53ef\u4ee5\u7528\u5341\u516d\u8fdb\u5236\u8fd9\u4e48\u5199<code>str<\/code>\uff1a<\/p>\n<pre><code class=\"python\"><span class=\"prompt\">&gt;&gt;&gt; <\/span><span class=\"string\">'\\u4e2d\\u6587'<\/span>\r\n<span class=\"string\">'\u4e2d\u6587'<\/span>\r\n<\/code><\/pre>\n<p>\u4e24\u79cd\u5199\u6cd5\u5b8c\u5168\u662f\u7b49\u4ef7\u7684\u3002<\/p>\n<p>\u7531\u4e8ePython\u7684\u5b57\u7b26\u4e32\u7c7b\u578b\u662f<code>str<\/code>\uff0c\u5728\u5185\u5b58\u4e2d\u4ee5Unicode\u8868\u793a\uff0c\u4e00\u4e2a\u5b57\u7b26\u5bf9\u5e94\u82e5\u5e72\u4e2a\u5b57\u8282\u3002\u5982\u679c\u8981\u5728\u7f51\u7edc\u4e0a\u4f20\u8f93\uff0c\u6216\u8005\u4fdd\u5b58\u5230\u78c1\u76d8\u4e0a\uff0c\u5c31\u9700\u8981\u628a<code>str<\/code>\u53d8\u4e3a\u4ee5\u5b57\u8282\u4e3a\u5355\u4f4d\u7684<code>bytes<\/code>\u3002<\/p>\n<p>Python\u5bf9<code>bytes<\/code>\u7c7b\u578b\u7684\u6570\u636e\u7528\u5e26<code>b<\/code>\u524d\u7f00\u7684\u5355\u5f15\u53f7\u6216\u53cc\u5f15\u53f7\u8868\u793a\uff1a<\/p>\n<pre><code class=\"ini\"><span class=\"setting\">x = <span class=\"value\">b'ABC'<\/span><\/span>\r\n<\/code><\/pre>\n<p>\u8981\u6ce8\u610f\u533a\u5206<code>'ABC'<\/code>\u548c<code>b'ABC'<\/code>\uff0c\u524d\u8005\u662f<code>str<\/code>\uff0c\u540e\u8005\u867d\u7136\u5185\u5bb9\u663e\u793a\u5f97\u548c\u524d\u8005\u4e00\u6837\uff0c\u4f46<code>bytes<\/code>\u7684\u6bcf\u4e2a\u5b57\u7b26\u90fd\u53ea\u5360\u7528\u4e00\u4e2a\u5b57\u8282\u3002<\/p>\n<p>\u4ee5Unicode\u8868\u793a\u7684<code>str<\/code>\u901a\u8fc7<code>encode()<\/code>\u65b9\u6cd5\u53ef\u4ee5\u7f16\u7801\u4e3a\u6307\u5b9a\u7684<code>bytes<\/code>\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre><code class=\"xml\">&gt;&gt;&gt; 'ABC'.encode('ascii')\r\nb'ABC'\r\n&gt;&gt;&gt; '\u4e2d\u6587'.encode('utf-8')\r\nb'\\xe4\\xb8\\xad\\xe6\\x96\\x87'\r\n&gt;&gt;&gt; '\u4e2d\u6587'.encode('ascii')\r\nTraceback (most recent call last):\r\n  File \"<span class=\"tag\">&lt;<span class=\"title\">stdin<\/span>&gt;<\/span>\", line 1, in <span class=\"tag\">&lt;<span class=\"title\">module<\/span>&gt;<\/span>\r\nUnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)\r\n<\/code><\/pre>\n<p>\u7eaf\u82f1\u6587\u7684<code>str<\/code>\u53ef\u4ee5\u7528<code>ASCII<\/code>\u7f16\u7801\u4e3a<code>bytes<\/code>\uff0c\u5185\u5bb9\u662f\u4e00\u6837\u7684\uff0c\u542b\u6709\u4e2d\u6587\u7684<code>str<\/code>\u53ef\u4ee5\u7528<code>UTF-8<\/code>\u7f16\u7801\u4e3a<code>bytes<\/code>\u3002\u542b\u6709\u4e2d\u6587\u7684<code>str<\/code>\u65e0\u6cd5\u7528<code>ASCII<\/code>\u7f16\u7801\uff0c\u56e0\u4e3a\u4e2d\u6587\u7f16\u7801\u7684\u8303\u56f4\u8d85\u8fc7\u4e86<code>ASCII<\/code>\u7f16\u7801\u7684\u8303\u56f4\uff0cPython\u4f1a\u62a5\u9519\u3002<\/p>\n<p>\u5728<code>bytes<\/code>\u4e2d\uff0c\u65e0\u6cd5\u663e\u793a\u4e3aASCII\u5b57\u7b26\u7684\u5b57\u8282\uff0c\u7528<code>\\x##<\/code>\u663e\u793a\u3002<\/p>\n<p>\u53cd\u8fc7\u6765\uff0c\u5982\u679c\u6211\u4eec\u4ece\u7f51\u7edc\u6216\u78c1\u76d8\u4e0a\u8bfb\u53d6\u4e86\u5b57\u8282\u6d41\uff0c\u90a3\u4e48\u8bfb\u5230\u7684\u6570\u636e\u5c31\u662f<code>bytes<\/code>\u3002\u8981\u628a<code>bytes<\/code>\u53d8\u4e3a<code>str<\/code>\uff0c\u5c31\u9700\u8981\u7528<code>decode()<\/code>\u65b9\u6cd5\uff1a<\/p>\n<pre><code class=\"python\"><span class=\"prompt\">&gt;&gt;&gt; <\/span><span class=\"string\">b'ABC'<\/span>.decode(<span class=\"string\">'ascii'<\/span>)\r\n<span class=\"string\">'ABC'<\/span>\r\n<span class=\"prompt\">&gt;&gt;&gt; <\/span><span class=\"string\">b'\\xe4\\xb8\\xad\\xe6\\x96\\x87'<\/span>.decode(<span class=\"string\">'utf-8'<\/span>)\r\n<span class=\"string\">'\u4e2d\u6587'<\/span>\r\n<\/code><\/pre>\n<p>\u8981\u8ba1\u7b97<code>str<\/code>\u5305\u542b\u591a\u5c11\u4e2a\u5b57\u7b26\uff0c\u53ef\u4ee5\u7528<code>len()<\/code>\u51fd\u6570\uff1a<\/p>\n<pre><code class=\"python\"><span class=\"prompt\">&gt;&gt;&gt; <\/span>len(<span class=\"string\">'ABC'<\/span>)\r\n<span class=\"number\">3<\/span>\r\n<span class=\"prompt\">&gt;&gt;&gt; <\/span>len(<span class=\"string\">'\u4e2d\u6587'<\/span>)\r\n<span class=\"number\">2<\/span>\r\n<\/code><\/pre>\n<p><code>len()<\/code>\u51fd\u6570\u8ba1\u7b97\u7684\u662f<code>str<\/code>\u7684\u5b57\u7b26\u6570\uff0c\u5982\u679c\u6362\u6210<code>bytes<\/code>\uff0c<code>len()<\/code>\u51fd\u6570\u5c31\u8ba1\u7b97\u5b57\u8282\u6570\uff1a<\/p>\n<pre><code class=\"python\"><span class=\"prompt\">&gt;&gt;&gt; <\/span>len(<span class=\"string\">b'ABC'<\/span>)\r\n<span class=\"number\">3<\/span>\r\n<span class=\"prompt\">&gt;&gt;&gt; <\/span>len(<span class=\"string\">b'\\xe4\\xb8\\xad\\xe6\\x96\\x87'<\/span>)\r\n<span class=\"number\">6<\/span>\r\n<span class=\"prompt\">&gt;&gt;&gt; <\/span>len(<span class=\"string\">'\u4e2d\u6587'<\/span>.encode(<span class=\"string\">'utf-8'<\/span>))\r\n<span class=\"number\">6<\/span>\r\n<\/code><\/pre>\n<p>\u53ef\u89c1\uff0c1\u4e2a\u4e2d\u6587\u5b57\u7b26\u7ecf\u8fc7UTF-8\u7f16\u7801\u540e\u901a\u5e38\u4f1a\u5360\u75283\u4e2a\u5b57\u8282\uff0c\u800c1\u4e2a\u82f1\u6587\u5b57\u7b26\u53ea\u5360\u75281\u4e2a\u5b57\u8282\u3002<\/p>\n<p>\u5728\u64cd\u4f5c\u5b57\u7b26\u4e32\u65f6\uff0c\u6211\u4eec\u7ecf\u5e38\u9047\u5230<code>str<\/code>\u548c<code>bytes<\/code>\u7684\u4e92\u76f8\u8f6c\u6362\u3002\u4e3a\u4e86\u907f\u514d\u4e71\u7801\u95ee\u9898\uff0c\u5e94\u5f53\u59cb\u7ec8\u575a\u6301\u4f7f\u7528UTF-8\u7f16\u7801\u5bf9<code>str<\/code>\u548c<code>bytes<\/code>\u8fdb\u884c\u8f6c\u6362\u3002<\/p>\n<p>\u7531\u4e8ePython\u6e90\u4ee3\u7801\u4e5f\u662f\u4e00\u4e2a\u6587\u672c\u6587\u4ef6\uff0c\u6240\u4ee5\uff0c\u5f53\u4f60\u7684\u6e90\u4ee3\u7801\u4e2d\u5305\u542b\u4e2d\u6587\u7684\u65f6\u5019\uff0c\u5728\u4fdd\u5b58\u6e90\u4ee3\u7801\u65f6\uff0c\u5c31\u9700\u8981\u52a1\u5fc5\u6307\u5b9a\u4fdd\u5b58\u4e3aUTF-8\u7f16\u7801\u3002\u5f53Python\u89e3\u91ca\u5668\u8bfb\u53d6\u6e90\u4ee3\u7801\u65f6\uff0c\u4e3a\u4e86\u8ba9\u5b83\u6309UTF-8\u7f16\u7801\u8bfb\u53d6\uff0c\u6211\u4eec\u901a\u5e38\u5728\u6587\u4ef6\u5f00\u5934\u5199\u4e0a\u8fd9\u4e24\u884c\uff1a<\/p>\n<pre><code class=\"ruby\"><span class=\"comment\">#!\/usr\/bin\/env python3<\/span>\r\n<span class=\"comment\"># -*- coding: utf-8 -*-<\/span>\r\n<\/code><\/pre>\n<p>\u7b2c\u4e00\u884c\u6ce8\u91ca\u662f\u4e3a\u4e86\u544a\u8bc9Linux\/OS X\u7cfb\u7edf\uff0c\u8fd9\u662f\u4e00\u4e2aPython\u53ef\u6267\u884c\u7a0b\u5e8f\uff0cWindows\u7cfb\u7edf\u4f1a\u5ffd\u7565\u8fd9\u4e2a\u6ce8\u91ca\uff1b<\/p>\n<p>\u7b2c\u4e8c\u884c\u6ce8\u91ca\u662f\u4e3a\u4e86\u544a\u8bc9Python\u89e3\u91ca\u5668\uff0c\u6309\u7167UTF-8\u7f16\u7801\u8bfb\u53d6\u6e90\u4ee3\u7801\uff0c\u5426\u5219\uff0c\u4f60\u5728\u6e90\u4ee3\u7801\u4e2d\u5199\u7684\u4e2d\u6587\u8f93\u51fa\u53ef\u80fd\u4f1a\u6709\u4e71\u7801\u3002<\/p>\n<p>\u7533\u660e\u4e86UTF-8\u7f16\u7801\u5e76\u4e0d\u610f\u5473\u7740\u4f60\u7684<code>.py<\/code>\u6587\u4ef6\u5c31\u662fUTF-8\u7f16\u7801\u7684\uff0c\u5fc5\u987b\u5e76\u4e14\u8981\u786e\u4fdd\u6587\u672c\u7f16\u8f91\u5668\u6b63\u5728\u4f7f\u7528UTF-8 without BOM\u7f16\u7801\u3002<\/p>\n<h3 id=\"-\">\u683c\u5f0f\u5316<\/h3>\n<p>\u6700\u540e\u4e00\u4e2a\u5e38\u89c1\u7684\u95ee\u9898\u662f\u5982\u4f55\u8f93\u51fa\u683c\u5f0f\u5316\u7684\u5b57\u7b26\u4e32\u3002\u6211\u4eec\u7ecf\u5e38\u4f1a\u8f93\u51fa\u7c7b\u4f3c<code>'\u4eb2\u7231\u7684xxx\u4f60\u597d\uff01\u4f60xx\u6708\u7684\u8bdd\u8d39\u662fxx\uff0c\u4f59\u989d\u662fxx'<\/code>\u4e4b\u7c7b\u7684\u5b57\u7b26\u4e32\uff0c\u800cxxx\u7684\u5185\u5bb9\u90fd\u662f\u6839\u636e\u53d8\u91cf\u53d8\u5316\u7684\uff0c\u6240\u4ee5\uff0c\u9700\u8981\u4e00\u79cd\u7b80\u4fbf\u7684\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u7684\u65b9\u5f0f\u3002<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.liaoxuefeng.com\/files\/attachments\/001389579690189985ca83044bd4aa7a80c47f9296a5c4e000\/0\" alt=\"py-str-format\" \/><\/p>\n<p>\u5728Python\u4e2d\uff0c\u91c7\u7528\u7684\u683c\u5f0f\u5316\u65b9\u5f0f\u548cC\u8bed\u8a00\u662f\u4e00\u81f4\u7684\uff0c\u7528<code>%<\/code>\u5b9e\u73b0\uff0c\u4e3e\u4f8b\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"python\"><span class=\"prompt\">&gt;&gt;&gt; <\/span><span class=\"string\">'Hello, %s'<\/span> % <span class=\"string\">'world'<\/span>\r\n<span class=\"string\">'Hello, world'<\/span>\r\n<span class=\"prompt\">&gt;&gt;&gt; <\/span><span class=\"string\">'Hi, %s, you have $%d.'<\/span> % (<span class=\"string\">'Michael'<\/span>, <span class=\"number\">1000000<\/span>)\r\n<span class=\"string\">'Hi, Michael, you have $1000000.'<\/span>\r\n<\/code><\/pre>\n<p>\u4f60\u53ef\u80fd\u731c\u5230\u4e86\uff0c<code>%<\/code>\u8fd0\u7b97\u7b26\u5c31\u662f\u7528\u6765\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u7684\u3002\u5728\u5b57\u7b26\u4e32\u5185\u90e8\uff0c<code>%s<\/code>\u8868\u793a\u7528\u5b57\u7b26\u4e32\u66ff\u6362\uff0c<code>%d<\/code>\u8868\u793a\u7528\u6574\u6570\u66ff\u6362\uff0c\u6709\u51e0\u4e2a<code>%?<\/code>\u5360\u4f4d\u7b26\uff0c\u540e\u9762\u5c31\u8ddf\u51e0\u4e2a\u53d8\u91cf\u6216\u8005\u503c\uff0c\u987a\u5e8f\u8981\u5bf9\u5e94\u597d\u3002\u5982\u679c\u53ea\u6709\u4e00\u4e2a<code>%?<\/code>\uff0c\u62ec\u53f7\u53ef\u4ee5\u7701\u7565\u3002<\/p>\n<p>\u5e38\u89c1\u7684\u5360\u4f4d\u7b26\u6709\uff1a<\/p>\n<table class=\"uk-table\">\n<tbody>\n<tr>\n<td>%d<\/td>\n<td>\u6574\u6570<\/td>\n<\/tr>\n<tr>\n<td>%f<\/td>\n<td>\u6d6e\u70b9\u6570<\/td>\n<\/tr>\n<tr>\n<td>%s<\/td>\n<td>\u5b57\u7b26\u4e32<\/td>\n<\/tr>\n<tr>\n<td>%x<\/td>\n<td>\u5341\u516d\u8fdb\u5236\u6574\u6570<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u5176\u4e2d\uff0c\u683c\u5f0f\u5316\u6574\u6570\u548c\u6d6e\u70b9\u6570\u8fd8\u53ef\u4ee5\u6307\u5b9a\u662f\u5426\u88650\u548c\u6574\u6570\u4e0e\u5c0f\u6570\u7684\u4f4d\u6570\uff1a<\/p>\n<pre><code class=\"python\"><span class=\"prompt\">&gt;&gt;&gt; <\/span><span class=\"string\">'%2d-%02d'<\/span> % (<span class=\"number\">3<\/span>, <span class=\"number\">1<\/span>)\r\n<span class=\"string\">' 3-01'<\/span>\r\n<span class=\"prompt\">&gt;&gt;&gt; <\/span><span class=\"string\">'%.2f'<\/span> % <span class=\"number\">3.1415926<\/span>\r\n<span class=\"string\">'3.14'<\/span>\r\n<\/code><\/pre>\n<p>\u5982\u679c\u4f60\u4e0d\u592a\u786e\u5b9a\u5e94\u8be5\u7528\u4ec0\u4e48\uff0c<code>%s<\/code>\u6c38\u8fdc\u8d77\u4f5c\u7528\uff0c\u5b83\u4f1a\u628a\u4efb\u4f55\u6570\u636e\u7c7b\u578b\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\uff1a<\/p>\n<pre><code class=\"python\"><span class=\"prompt\">&gt;&gt;&gt; <\/span><span class=\"string\">'Age: %s. Gender: %s'<\/span> % (<span class=\"number\">25<\/span>, <span class=\"built_in\">True<\/span>)\r\n<span class=\"string\">'Age: 25. Gender: True'<\/span>\r\n<\/code><\/pre>\n<p>\u6709\u4e9b\u65f6\u5019\uff0c\u5b57\u7b26\u4e32\u91cc\u9762\u7684<code>%<\/code>\u662f\u4e00\u4e2a\u666e\u901a\u5b57\u7b26\u600e\u4e48\u529e\uff1f\u8fd9\u4e2a\u65f6\u5019\u5c31\u9700\u8981\u8f6c\u4e49\uff0c\u7528<code>%%<\/code>\u6765\u8868\u793a\u4e00\u4e2a<code>%<\/code>\uff1a<\/p>\n<pre><code class=\"python\"><span class=\"prompt\">&gt;&gt;&gt; <\/span><span class=\"string\">'growth rate: %d %%'<\/span> % <span class=\"number\">7<\/span>\r\n<span class=\"string\">'growth rate: 7 %'<\/span><\/code><\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Python\u63d0\u4f9b\u4e86ord()\u51fd\u6570\u83b7\u53d6\u5b57\u7b26\u7684\u6574\u6570\u8868\u793a\uff0cchr()\u51fd\u6570\u628a\u7f16\u7801\u8f6c\u6362\u4e3a\u5bf9\u5e94\u7684\u5b57\u7b26\u3002 &gt;&gt;&#038; &hellip; <a href=\"https:\/\/blog.la998.com\/?p=223\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">python \u5b57\u7b26\u4e32\u548c\u7f16\u7801<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-223","post","type-post","status-publish","format-standard","hentry","category-python"],"_links":{"self":[{"href":"https:\/\/blog.la998.com\/index.php?rest_route=\/wp\/v2\/posts\/223","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.la998.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.la998.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.la998.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.la998.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=223"}],"version-history":[{"count":1,"href":"https:\/\/blog.la998.com\/index.php?rest_route=\/wp\/v2\/posts\/223\/revisions"}],"predecessor-version":[{"id":224,"href":"https:\/\/blog.la998.com\/index.php?rest_route=\/wp\/v2\/posts\/223\/revisions\/224"}],"wp:attachment":[{"href":"https:\/\/blog.la998.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=223"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.la998.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=223"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.la998.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=223"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}