{"id":172695,"date":"2022-04-17T22:39:05","date_gmt":"2022-04-17T14:39:05","guid":{"rendered":"http:\/\/www.idc.net\/help\/172695\/"},"modified":"2022-04-17T22:39:05","modified_gmt":"2022-04-17T14:39:05","slug":"%e5%90%8e%e6%b5%aa%e4%ba%91python%e6%95%99%e7%a8%8b%ef%bc%9apython%e4%b8%ad%e5%ad%97%e7%ac%a6%e7%bc%96%e7%a0%81%e6%98%af%e4%bb%80%e4%b9%88%ef%bc%9f%e5%a6%82%e4%bd%95%e8%bd%ac%e6%8d%a2%e5%ad%97","status":"publish","type":"post","link":"https:\/\/idc.net\/help\/172695\/","title":{"rendered":"\u540e\u6d6a\u4e91Python\u6559\u7a0b\uff1apython\u4e2d\u5b57\u7b26\u7f16\u7801\u662f\u4ec0\u4e48\uff1f\u5982\u4f55\u8f6c\u6362\u5b57\u7b26?"},"content":{"rendered":"<p style=\"text-align:center\"><span style=\"font-family: \u5fae\u8f6f\u96c5\u9ed1;font-size: 16px\"><img decoding=\"async\" src=\"https:\/\/oss.py.cn\/pycn\/upload\/image\/216\/285\/124\/1607254093897120.png\" class=\"aligncenter\"><\/span><\/p>\n<p style=\"line-height: 1.75em\"><span style=\"font-family: \u5fae\u8f6f\u96c5\u9ed1;font-size: 16px\">\u5c4f\u5e55\u524d\u6211\u4eec\u770b\u5230\u7684\u6587\u5b57\uff0c\u5728\u8ba1\u7b97\u673a\u4e2d\u4e5f\u662f\u8fd9\u6837\u8868\u793a\u5417\uff1f\u4e8b\u5b9e\u4e0a\uff0c\u6211\u4eec\u6240\u6709\u7684\u4fe1\u606f\u7535\u8111\u662f\u65e0\u6cd5\u76f4\u63a5\u7406\u89e3\u7684\uff0c\u540c\u6837\u6211\u4eec\u6240\u8981\u8868\u8fbe\u7684\u4fe1\u606f\uff0c\u8ba1\u7b97\u673a\u4e5f\u4e0d\u80fd\u770b\u61c2\u3002\u8fd9\u5c31\u9700\u8981\u67b6\u8d77\u4e00\u4e2a\u7406\u89e3\u7684\u6865\u6881\uff0c\u4e5f\u5c31\u662f\u7f16\u7801\u5e2e\u52a9\u6211\u4eec\u76f8\u4e92\u4e4b\u95f4\u8fdb\u884c\u7ffb\u8bd1\u3002\u4eca\u5929\u5c0f\u7f16\u5c31python\u4e2d\u7684\u5b57\u7b26\u7f16\u7801\u95ee\u9898\u4e3a\u5e26\u6765\u8bb2\u89e3\uff0c\u540c\u65f6\u6559\u5927\u5bb6\u8f6c\u6362\u5b57\u7b26\u7684\u65b9\u6cd5\u3002<\/span><\/p>\n<p style=\"line-height: 1.75em\"><span style=\"font-family: \u5fae\u8f6f\u96c5\u9ed1,Microsoft YaHei;font-size: 14px\"><span style=\"font-family: \u5fae\u8f6f\u96c5\u9ed1;font-size: 14px\">\u5b57\u7b26\u7f16\u7801\uff08<\/span>Character Encoding\uff09\u662f\u5c06\u5b57\u7b26\u96c6\u4e2d\u7684\u5b57\u7b26\u7801\u6620\u5c04\u4e3a\u5b57\u8282\u6d41\u7684\u4e00\u79cd\u5177\u4f53\u5b9e\u73b0\u65b9\u6848\uff0c\u5e38\u89c1\u7684\u5b57\u7b26\u7f16\u7801\u6709 ASCII \u7f16\u7801\u3001UTF-8 \u7f16\u7801\u3001GBK \u7f16\u7801\u7b49\u3002\u67d0\u79cd\u610f\u4e49\u4e0a\u6765\u8bf4\uff0c\u5b57\u7b26\u96c6\u4e0e\u5b57\u7b26\u7f16\u7801\u6709\u79cd\u5bf9\u5e94\u5173\u7cfb\uff0c\u4f8b\u5982 ASCII \u5b57\u7b26\u96c6\u5bf9\u5e94 \u6709 ASCII \u7f16\u7801\u3002ASCII \u5b57\u7b26\u7f16\u7801\u89c4\u5b9a\u4f7f\u7528\u5355\u5b57\u8282\u4e2d\u4f4e\u4f4d\u76847\u4e2a\u6bd4\u7279\u53bb\u7f16\u7801\u6240\u6709\u7684\u5b57\u7b26\u3002\u4f8b\u5982\"A\" \u7684\u7f16\u53f7\u662f65\uff0c\u7528\u5355\u5b57\u8282\u8868\u793a\u5c31\u662f0\u00d741\uff0c\u56e0\u6b64\u5199\u5165\u5b58\u50a8\u8bbe\u5907\u7684\u65f6\u5019\u5c31\u662fb'01000001'\u3002<\/span><\/p>\n<p style=\"line-height: 1.75em\"><span style=\"font-family: \u5fae\u8f6f\u96c5\u9ed1,Microsoft YaHei;font-size: 14px\"><span style=\"font-family: \u5fae\u8f6f\u96c5\u9ed1;font-size: 14px\">\u5728\u6700\u65b0\u7684<\/span> Python 3 \u7248\u672c\u4e2d\uff0c\u6240\u6709\u5b57\u7b26\u4e32\u90fd\u4ee5Unicode \u8fdb\u884c\u7f16\u7801\u3002\u56e0\u6b64\uff0cPython3 \u7684\u5b57\u7b26\u4e32\u9ed8\u8ba4\u652f\u6301\u591a\u8bed\u8a00\u3002\u58f0\u660e\u5b57\u7b26\u4e32\u53ef\u4ee5\u4f7f\u7528\u5355\u5f15\u53f7\u548c\u53cc\u5f15\u53f7<\/span><\/p>\n<pre>&gt;&gt;&gt;&nbsp;a&nbsp;=&nbsp;\"apple\"\n&gt;&gt;&gt;&nbsp;b&nbsp;=&nbsp;'banana'\n&gt;&gt;&gt;&nbsp;print('\u5305\u542b\u4e2d\u6587\u7684str')\n\u5305\u542b\u4e2d\u6587\u7684str<\/pre>\n<p style=\"line-height: 1.75em\"><span style=\"font-family: \u5fae\u8f6f\u96c5\u9ed1,Microsoft YaHei;font-size: 14px\"><span style=\"font-family: \u5fae\u8f6f\u96c5\u9ed1;font-size: 14px\">\u5bf9\u4e8e\u5355\u4e2a\u5b57\u7b26\u7684\u7f16\u7801\uff0c<\/span>Python\u63d0\u4f9b\u4e86 ord() \u51fd\u6570\u83b7\u53d6\u5b57\u7b26\u7684\u5341\u8fdb\u5236\u6574\u6570\u8868\u793a\uff0cchr() \u51fd\u6570\u628a\u7f16\u7801\u8f6c\u6362\u4e3a\u5bf9\u5e94\u7684\u5b57\u7b26\uff1a<\/span><\/p>\n<pre>&gt;&gt;&gt;&nbsp;ord('A')\n65\n&gt;&gt;&gt;&nbsp;ord('\u4e2d')\n20013\n&gt;&gt;&gt;&nbsp;chr(66)\n'B'\n&gt;&gt;&gt;&nbsp;chr(25991)\n'\u6587'<\/pre>\n<p style=\"line-height: 1.75em\"><span style=\"font-family: \u5fae\u8f6f\u96c5\u9ed1,Microsoft YaHei;font-size: 14px\"><span style=\"font-family: \u5fae\u8f6f\u96c5\u9ed1;font-size: 14px\">\u5982\u679c\u77e5\u9053\u5b57\u7b26\u7684\u6574\u6570\u7f16\u7801\uff0c\u8fd8\u53ef\u4ee5\u7528\u5341\u516d\u8fdb\u5236\u5199<\/span> str\uff0c\u4e24\u79cd\u5199\u6cd5\u5b8c\u5168\u662f\u7b49\u4ef7\u7684\u3002<\/span><\/p>\n<pre>&gt;&gt;&gt;&nbsp;'\\u4e2d\\u6587'\n'\u4e2d\u6587'\n&gt;&gt;&gt;&nbsp;'\\u4e2d\\u6587'&nbsp;==&nbsp;'\u4e2d\u6587'\nTrue<\/pre>\n<p style=\"line-height: 1.75em\"><\/p>\n<p style=\"line-height: 1.75em\"><span style=\"font-family: \u5fae\u8f6f\u96c5\u9ed1,Microsoft YaHei;font-size: 16px\">\u901a\u8fc7\u5b57\u7b26\u7f16\u7801\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u5bf9\u8ba1\u7b97\u673a\u7684\u6570\u636e\u8fdb\u884c\u8f6c\u6362\uff0c\u5f53\u7136\u4e5f\u53ef\u4ee5\u628a\u6211\u4eec\u7684\u6570\u636e\u8f6c\u6362\u6210\u8ba1\u7b97\u673a\u673a\u8bed\u8a00\u4fdd\u5b58\u8d77\u6765\uff0c\u89c9\u5f97\u5b9e\u7528\u7684\u5c0f\u4f19\u4f34\u8d76\u7d27\u5b66\u8d77\u6765\u5427\u3002<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5c4f\u5e55\u524d\u6211\u4eec\u770b\u5230\u7684\u6587\u5b57\uff0c\u5728\u8ba1\u7b97\u673a\u4e2d\u4e5f\u662f\u8fd9\u6837\u8868\u793a\u5417\uff1f\u4e8b\u5b9e\u4e0a\uff0c\u6211\u4eec\u6240\u6709\u7684\u4fe1\u606f\u7535\u8111\u662f\u65e0\u6cd5\u76f4\u63a5\u7406\u89e3\u7684\uff0c\u540c\u6837\u6211\u4eec\u6240\u8981\u8868\u8fbe\u7684 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":172696,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[182397],"tags":[],"class_list":["post-172695","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python"],"_links":{"self":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/172695","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/comments?post=172695"}],"version-history":[{"count":0,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/172695\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media\/172696"}],"wp:attachment":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media?parent=172695"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/categories?post=172695"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/tags?post=172695"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}