{"id":922974,"date":"2024-12-26T14:41:39","date_gmt":"2024-12-26T06:41:39","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/922974.html"},"modified":"2024-12-26T14:41:41","modified_gmt":"2024-12-26T06:41:41","slug":"python%e5%a6%82%e4%bd%95%e5%88%a4%e6%96%ad%e5%ad%97%e7%ac%a6%e4%b8%b2%e7%9b%b8%e7%ad%89","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/922974.html","title":{"rendered":"python\u5982\u4f55\u5224\u65ad\u5b57\u7b26\u4e32\u76f8\u7b49"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24211236\/bfc0ee67-00da-4fea-b884-51fdb5d2408e.webp\" alt=\"python\u5982\u4f55\u5224\u65ad\u5b57\u7b26\u4e32\u76f8\u7b49\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\u5224\u65ad\u5b57\u7b26\u4e32\u76f8\u7b49\u53ef\u4ee5\u4f7f\u7528\u201c==\u201d\u8fd0\u7b97\u7b26\u3001\u4f7f\u7528\u201cis\u201d\u5173\u952e\u5b57\u3001\u4f7f\u7528str.compare()\u65b9\u6cd5\u3001\u5ffd\u7565\u5927\u5c0f\u5199\u6bd4\u8f83\u7b49\u65b9\u6cd5\u3002\u6700\u5e38\u7528\u7684\u65b9\u6cd5\u662f\u4f7f\u7528\u201c==\u201d\u8fd0\u7b97\u7b26\u3002<\/strong><\/p>\n<\/p>\n<p><p>Python\u662f\u4e00\u79cd\u5e7f\u6cdb\u4f7f\u7528\u7684\u7f16\u7a0b\u8bed\u8a00\uff0c\u652f\u6301\u591a\u79cd\u5b57\u7b26\u4e32\u64cd\u4f5c\u3002\u5728\u5224\u65ad\u5b57\u7b26\u4e32\u662f\u5426\u76f8\u7b49\u65f6\uff0c\u901a\u5e38\u4f7f\u7528\u201c==\u201d\u8fd0\u7b97\u7b26\uff0c\u56e0\u4e3a\u5b83\u80fd\u591f\u51c6\u786e\u5730\u6bd4\u8f83\u4e24\u4e2a\u5b57\u7b26\u4e32\u7684\u5185\u5bb9\u662f\u5426\u76f8\u540c\u3002\u76f8\u6bd4\u4e4b\u4e0b\uff0c\u4f7f\u7528\u201cis\u201d\u5173\u952e\u5b57\u6765\u5224\u65ad\u5b57\u7b26\u4e32\u76f8\u7b49\u662f\u9519\u8bef\u7684\u505a\u6cd5\uff0c\u56e0\u4e3a\u201cis\u201d\u7528\u4e8e\u5224\u65ad\u4e24\u4e2a\u5bf9\u8c61\u662f\u5426\u662f\u540c\u4e00\u4e2a\u5bf9\u8c61\uff0c\u800c\u4e0d\u662f\u5185\u5bb9\u76f8\u7b49\u3002\u6b64\u5916\uff0c\u8fd8\u53ef\u4ee5\u901a\u8fc7\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u76f8\u540c\u7684\u5927\u5c0f\u5199\u6765\u8fdb\u884c\u4e0d\u533a\u5206\u5927\u5c0f\u5199\u7684\u6bd4\u8f83\u3002<\/p>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u63a2\u8ba8\u4e0d\u540c\u65b9\u6cd5\u5728\u5224\u65ad\u5b57\u7b26\u4e32\u76f8\u7b49\u4e2d\u7684\u4f7f\u7528\u573a\u666f\u548c\u6ce8\u610f\u4e8b\u9879\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528\u201c==\u201d\u8fd0\u7b97\u7b26\u5224\u65ad\u5b57\u7b26\u4e32\u76f8\u7b49<\/h3>\n<\/p>\n<p><p>\u201c==\u201d\u8fd0\u7b97\u7b26\u662f\u5224\u65ad\u5b57\u7b26\u4e32\u76f8\u7b49\u7684\u6700\u7b80\u5355\u548c\u76f4\u63a5\u7684\u65b9\u6cd5\u3002\u5b83\u7528\u4e8e\u6bd4\u8f83\u4e24\u4e2a\u5b57\u7b26\u4e32\u7684\u5185\u5bb9\uff0c\u5982\u679c\u5185\u5bb9\u76f8\u540c\uff0c\u5219\u8fd4\u56deTrue\uff0c\u5426\u5219\u8fd4\u56deFalse\u3002<\/p>\n<\/p>\n<p><h4>1. \u57fa\u672c\u7528\u6cd5<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">string1 = &quot;Hello&quot;<\/p>\n<p>string2 = &quot;Hello&quot;<\/p>\n<p>string3 = &quot;hello&quot;<\/p>\n<p>print(string1 == string2)  # \u8f93\u51fa: True<\/p>\n<p>print(string1 == string3)  # \u8f93\u51fa: False<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c<code>string1<\/code>\u548c<code>string2<\/code>\u7684\u5185\u5bb9\u76f8\u540c\uff0c\u6240\u4ee5<code>string1 == string2<\/code>\u8fd4\u56deTrue\u3002\u800c<code>string1<\/code>\u548c<code>string3<\/code>\u7531\u4e8e\u5927\u5c0f\u5199\u4e0d\u540c\uff0c\u6240\u4ee5<code>string1 == string3<\/code>\u8fd4\u56deFalse\u3002<\/p>\n<\/p>\n<p><h4>2. \u6ce8\u610f\u4e8b\u9879<\/h4>\n<\/p>\n<ul>\n<li><strong>\u5927\u5c0f\u5199\u654f\u611f<\/strong>\uff1a\u4f7f\u7528\u201c==\u201d\u8fdb\u884c\u6bd4\u8f83\u65f6\u662f\u5927\u5c0f\u5199\u654f\u611f\u7684\uff0c\u56e0\u6b64\u9700\u8981\u786e\u4fdd\u5b57\u7b26\u4e32\u5185\u5bb9\u548c\u5927\u5c0f\u5199\u5b8c\u5168\u4e00\u81f4\u3002<\/li>\n<li><strong>\u7c7b\u578b\u4e00\u81f4\u6027<\/strong>\uff1a\u786e\u4fdd\u6bd4\u8f83\u7684\u4e24\u4e2a\u5bf9\u8c61\u90fd\u662f\u5b57\u7b26\u4e32\u7c7b\u578b\uff0c\u5426\u5219\u6bd4\u8f83\u7ed3\u679c\u53ef\u80fd\u4e0d\u7b26\u5408\u9884\u671f\u3002<\/li>\n<\/ul>\n<p><h3>\u4e8c\u3001\u4f7f\u7528\u201cis\u201d\u5173\u952e\u5b57\u8fdb\u884c\u5bf9\u8c61\u6bd4\u8f83<\/h3>\n<\/p>\n<p><p>\u867d\u7136\u201cis\u201d\u5173\u952e\u5b57\u53ef\u4ee5\u7528\u4e8e\u6bd4\u8f83\uff0c\u4f46\u5b83\u7528\u4e8e\u5224\u65ad\u4e24\u4e2a\u5bf9\u8c61\u662f\u5426\u4e3a\u540c\u4e00\u5bf9\u8c61\uff0c\u800c\u4e0d\u662f\u5224\u65ad\u5185\u5bb9\u662f\u5426\u76f8\u7b49\u3002\u56e0\u6b64\uff0c\u901a\u5e38\u4e0d\u7528\u4e8e\u5b57\u7b26\u4e32\u5185\u5bb9\u7684\u6bd4\u8f83\u3002<\/p>\n<\/p>\n<p><h4>1. \u793a\u4f8b<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">string1 = &quot;Hello&quot;<\/p>\n<p>string2 = &quot;Hello&quot;<\/p>\n<p>string3 = string1<\/p>\n<p>print(string1 is string2)  # \u8f93\u51fa: True \u6216 False \u53d6\u51b3\u4e8ePython\u7684\u5b9e\u73b0<\/p>\n<p>print(string1 is string3)  # \u8f93\u51fa: True<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ul>\n<li><strong>\u5bf9\u8c61\u6807\u8bc6<\/strong>\uff1a<code>string1 is string3<\/code>\u8fd4\u56deTrue\uff0c\u56e0\u4e3a<code>string3<\/code>\u662f<code>string1<\/code>\u7684\u5f15\u7528\u3002<\/li>\n<li><strong>\u4e0d\u5efa\u8bae\u7528\u4e8e\u5185\u5bb9\u6bd4\u8f83<\/strong>\uff1a<code>string1 is string2<\/code>\u7684\u7ed3\u679c\u53ef\u80fd\u4f9d\u8d56\u4e8ePython\u7684\u5185\u90e8\u4f18\u5316\uff0c\u4e0d\u5efa\u8bae\u7528\u4e8e\u5224\u65ad\u5b57\u7b26\u4e32\u5185\u5bb9\u76f8\u7b49\u3002<\/li>\n<\/ul>\n<p><h3>\u4e09\u3001\u5ffd\u7565\u5927\u5c0f\u5199\u7684\u5b57\u7b26\u4e32\u6bd4\u8f83<\/h3>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u9700\u8981\u5ffd\u7565\u5927\u5c0f\u5199\u6765\u6bd4\u8f83\u5b57\u7b26\u4e32\u3002\u53ef\u4ee5\u901a\u8fc7\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u76f8\u540c\u7684\u5927\u5c0f\u5199\uff08\u5982\u5168\u90e8\u5c0f\u5199\u6216\u5168\u90e8\u5927\u5199\uff09\u6765\u5b9e\u73b0\u3002<\/p>\n<\/p>\n<p><h4>1. \u4f7f\u7528<code>lower()<\/code>\u6216<code>upper()<\/code>\u65b9\u6cd5<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">string1 = &quot;Hello&quot;<\/p>\n<p>string2 = &quot;hello&quot;<\/p>\n<p>print(string1.lower() == string2.lower())  # \u8f93\u51fa: True<\/p>\n<p>print(string1.upper() == string2.upper())  # \u8f93\u51fa: True<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ul>\n<li><strong>\u8f6c\u6362\u5927\u5c0f\u5199<\/strong>\uff1a\u901a\u8fc7<code>lower()<\/code>\u6216<code>upper()<\/code>\u65b9\u6cd5\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u7edf\u4e00\u7684\u5927\u5c0f\u5199\uff0c\u4ece\u800c\u5b9e\u73b0\u4e0d\u533a\u5206\u5927\u5c0f\u5199\u7684\u6bd4\u8f83\u3002<\/li>\n<\/ul>\n<p><h3>\u56db\u3001\u4f7f\u7528str.compare()\u65b9\u6cd5\uff08Python 3.10\u4ee5\u4e0a\uff09<\/h3>\n<\/p>\n<p><p>Python 3.10\u5f15\u5165\u4e86\u65b0\u7684\u5b57\u7b26\u4e32\u65b9\u6cd5\u5982<code>str.casefold()<\/code>\uff0c\u53ef\u4ee5\u7528\u4e8e\u66f4\u9ad8\u7ea7\u7684\u5b57\u7b26\u4e32\u6bd4\u8f83\u3002<\/p>\n<\/p>\n<p><h4>1. \u4f7f\u7528<code>casefold()<\/code>\u8fdb\u884c\u6bd4\u8f83<\/h4>\n<\/p>\n<p><p><code>casefold()<\/code>\u65b9\u6cd5\u662f\u7528\u4e8e\u5ffd\u7565\u5927\u5c0f\u5199\u7684\u6bd4\u8f83\u7684\u66f4\u5f3a\u5927\u7248\u672c\uff0c\u9002\u7528\u4e8e\u591a\u8bed\u8a00\u6587\u672c\u5904\u7406\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">string1 = &quot;Stra\u00dfe&quot;<\/p>\n<p>string2 = &quot;strasse&quot;<\/p>\n<p>print(string1.casefold() == string2.casefold())  # \u8f93\u51fa: True<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ul>\n<li><strong>\u591a\u8bed\u8a00\u652f\u6301<\/strong>\uff1a<code>casefold()<\/code>\u65b9\u6cd5\u7279\u522b\u9002\u5408\u5904\u7406\u56fd\u9645\u5316\u6587\u672c\uff0c\u56e0\u4e3a\u5b83\u652f\u6301\u66f4\u590d\u6742\u7684\u5927\u5c0f\u5199\u8f6c\u6362\u89c4\u5219\u3002<\/li>\n<\/ul>\n<p><h3>\u4e94\u3001\u5176\u4ed6\u6bd4\u8f83\u6280\u672f<\/h3>\n<\/p>\n<p><p>\u9664\u4e86\u76f4\u63a5\u6bd4\u8f83\uff0c\u8fd8\u6709\u5176\u4ed6\u6280\u672f\u53ef\u4ee5\u7528\u4e8e\u5b57\u7b26\u4e32\u76f8\u7b49\u5224\u65ad\uff0c\u7279\u522b\u662f\u5728\u5904\u7406\u590d\u6742\u7684\u6587\u672c\u5206\u6790\u65f6\u3002<\/p>\n<\/p>\n<p><h4>1. \u6b63\u5219\u8868\u8fbe\u5f0f<\/h4>\n<\/p>\n<p><p>\u6b63\u5219\u8868\u8fbe\u5f0f\u662f\u7528\u4e8e\u6a21\u5f0f\u5339\u914d\u7684\u5f3a\u5927\u5de5\u5177\uff0c\u9002\u5408\u5728\u9700\u8981\u8fdb\u884c\u590d\u6742\u6a21\u5f0f\u5339\u914d\u65f6\u4f7f\u7528\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import re<\/p>\n<p>pattern = r&quot;hello&quot;<\/p>\n<p>string1 = &quot;Hello, world!&quot;<\/p>\n<h2><strong>\u5ffd\u7565\u5927\u5c0f\u5199\u7684\u5339\u914d<\/strong><\/h2>\n<p>match = re.search(pattern, string1, re.IGNORECASE)<\/p>\n<p>print(match is not None)  # \u8f93\u51fa: True<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ul>\n<li><strong>\u6a21\u5f0f\u5339\u914d<\/strong>\uff1a\u6b63\u5219\u8868\u8fbe\u5f0f\u4e0d\u4ec5\u7528\u4e8e\u5224\u65ad\u76f8\u7b49\uff0c\u8fd8\u53ef\u4ee5\u7528\u4e8e\u66f4\u590d\u6742\u7684\u6a21\u5f0f\u5339\u914d\u548c\u6587\u672c\u5904\u7406\u3002<\/li>\n<\/ul>\n<p><h4>2. \u4f7f\u7528Levenshtein\u8ddd\u79bb<\/h4>\n<\/p>\n<p><p>Levenshtein\u8ddd\u79bb\u7528\u4e8e\u8ba1\u7b97\u4e24\u4e2a\u5b57\u7b26\u4e32\u4e4b\u95f4\u7684\u6700\u5c0f\u7f16\u8f91\u8ddd\u79bb\uff0c\u9002\u5408\u4e8e\u6a21\u7cca\u5339\u914d\u573a\u666f\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from Levenshtein import distance<\/p>\n<p>string1 = &quot;kitten&quot;<\/p>\n<p>string2 = &quot;sitting&quot;<\/p>\n<p>print(distance(string1, string2))  # \u8f93\u51fa: 3<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ul>\n<li><strong>\u6a21\u7cca\u5339\u914d<\/strong>\uff1a\u7528\u4e8e\u5224\u65ad\u4e24\u4e2a\u5b57\u7b26\u4e32\u7684\u76f8\u4f3c\u5ea6\u800c\u975e\u7cbe\u786e\u76f8\u7b49\u3002<\/li>\n<\/ul>\n<p><h3>\u516d\u3001\u6027\u80fd\u8003\u8651<\/h3>\n<\/p>\n<p><p>\u5728\u5904\u7406\u5927\u91cf\u5b57\u7b26\u4e32\u6bd4\u8f83\u65f6\uff0c\u6027\u80fd\u662f\u4e00\u4e2a\u9700\u8981\u8003\u8651\u7684\u91cd\u8981\u56e0\u7d20\u3002\u4e0d\u540c\u7684\u65b9\u6cd5\u5728\u6027\u80fd\u4e0a\u53ef\u80fd\u4f1a\u6709\u5dee\u5f02\u3002<\/p>\n<\/p>\n<p><h4>1. \u76f4\u63a5\u6bd4\u8f83 vs \u6b63\u5219\u8868\u8fbe\u5f0f<\/h4>\n<\/p>\n<p><p>\u76f4\u63a5\u6bd4\u8f83\u901a\u5e38\u6bd4\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d\u66f4\u9ad8\u6548\uff0c\u56e0\u4e3a\u6b63\u5219\u8868\u8fbe\u5f0f\u5f15\u64ce\u9700\u8981\u89e3\u6790\u548c\u5339\u914d\u6a21\u5f0f\u3002<\/p>\n<\/p>\n<p><h4>2. \u5b57\u7b26\u4e32\u7f13\u5b58\u673a\u5236<\/h4>\n<\/p>\n<p><p>Python\u6709\u5b57\u7b26\u4e32\u7f13\u5b58\u673a\u5236\uff08interning\uff09\uff0c\u5bf9\u4e8e\u77ed\u5c0f\u7684\u5b57\u7b26\u4e32\uff0c\u53ef\u80fd\u4f1a\u81ea\u52a8\u7f13\u5b58\u4ee5\u63d0\u9ad8\u6027\u80fd\u3002\u4f46\u8fd9\u4e0d\u5e94\u88ab\u7528\u4e8e\u5224\u65ad\u5b57\u7b26\u4e32\u76f8\u7b49\u3002<\/p>\n<\/p>\n<p><h3>\u4e03\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5224\u65ad\u5b57\u7b26\u4e32\u76f8\u7b49\u5728Python\u4e2d\u662f\u4e00\u4e2a\u5e38\u89c1\u7684\u4efb\u52a1\uff0c\u6709\u591a\u79cd\u65b9\u6cd5\u53ef\u4ee5\u5b9e\u73b0\u3002\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u53d6\u51b3\u4e8e\u5177\u4f53\u7684\u5e94\u7528\u573a\u666f\u548c\u9700\u6c42\u3002\u5bf9\u4e8e\u7b80\u5355\u7684\u7cbe\u786e\u6bd4\u8f83\uff0c\u4f7f\u7528\u201c==\u201d\u8fd0\u7b97\u7b26\u662f\u6700\u76f4\u63a5\u548c\u9ad8\u6548\u7684\u9009\u62e9\u3002\u800c\u5728\u5904\u7406\u9700\u8981\u5ffd\u7565\u5927\u5c0f\u5199\u6216\u8fdb\u884c\u6a21\u5f0f\u5339\u914d\u7684\u573a\u666f\u65f6\uff0c\u8003\u8651\u4f7f\u7528<code>lower()<\/code>\u3001<code>casefold()<\/code>\u6216\u6b63\u5219\u8868\u8fbe\u5f0f\u7b49\u66f4\u590d\u6742\u7684\u65b9\u6cd5\u3002\u4e86\u89e3\u4e0d\u540c\u65b9\u6cd5\u7684\u6027\u80fd\u7279\u70b9\u548c\u9002\u7528\u573a\u666f\uff0c\u80fd\u591f\u5e2e\u52a9\u6211\u4eec\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\u66f4\u9ad8\u6548\u5730\u5904\u7406\u5b57\u7b26\u4e32\u6bd4\u8f83\u95ee\u9898\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u6bd4\u8f83\u4e24\u4e2a\u5b57\u7b26\u4e32\u662f\u5426\u76f8\u7b49\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u201c==\u201d\u8fd0\u7b97\u7b26\u76f4\u63a5\u6bd4\u8f83\u4e24\u4e2a\u5b57\u7b26\u4e32\u3002\u5982\u679c\u4e24\u4e2a\u5b57\u7b26\u4e32\u7684\u5185\u5bb9\u5b8c\u5168\u76f8\u540c\uff0c\u8fd4\u56de\u503c\u4e3aTrue\uff1b\u5426\u5219\u8fd4\u56deFalse\u3002\u6b64\u5916\uff0c\u4f7f\u7528<code>str.equals()<\/code>\u65b9\u6cd5\u4e5f\u53ef\u4ee5\u8fdb\u884c\u5b57\u7b26\u4e32\u7684\u6bd4\u8f83\uff0c\u5b83\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\u80fd\u591f\u63d0\u4f9b\u66f4\u5f3a\u7684\u6bd4\u8f83\u80fd\u529b\u3002<\/p>\n<p><strong>Python\u4e2d\u5b57\u7b26\u4e32\u6bd4\u8f83\u662f\u533a\u5206\u5927\u5c0f\u5199\u7684\u5417\uff1f<\/strong><br \/>\u662f\u7684\uff0cPython\u4e2d\u7684\u5b57\u7b26\u4e32\u6bd4\u8f83\u662f\u533a\u5206\u5927\u5c0f\u5199\u7684\u3002\u4f8b\u5982\uff0c\u201cHello\u201d\u548c\u201chello\u201d\u88ab\u8ba4\u4e3a\u662f\u4e0d\u540c\u7684\u5b57\u7b26\u4e32\u3002\u5982\u679c\u9700\u8981\u8fdb\u884c\u4e0d\u533a\u5206\u5927\u5c0f\u5199\u7684\u6bd4\u8f83\uff0c\u53ef\u4ee5\u5c06\u4e24\u4e2a\u5b57\u7b26\u4e32\u90fd\u8f6c\u6362\u4e3a\u5c0f\u5199\u6216\u5927\u5199\u540e\u518d\u8fdb\u884c\u6bd4\u8f83\uff0c\u4f8b\u5982\u4f7f\u7528<code>str.lower()<\/code>\u6216<code>str.upper()<\/code>\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u5982\u4f55\u5904\u7406\u5b57\u7b26\u4e32\u6bd4\u8f83\u65f6\u7684\u7a7a\u767d\u5b57\u7b26\uff1f<\/strong><br \/>\u5728\u6bd4\u8f83\u5b57\u7b26\u4e32\u65f6\uff0c\u5982\u679c\u5b58\u5728\u7a7a\u767d\u5b57\u7b26\uff0c\u4f1a\u5f71\u54cd\u6bd4\u8f83\u7ed3\u679c\u3002\u53ef\u4ee5\u4f7f\u7528<code>str.strip()<\/code>\u65b9\u6cd5\u53bb\u9664\u5b57\u7b26\u4e32\u9996\u5c3e\u7684\u7a7a\u767d\u5b57\u7b26\uff0c\u7136\u540e\u518d\u8fdb\u884c\u6bd4\u8f83\u3002\u4f8b\u5982\uff0c\u5c06<code>&quot;  example  &quot;.strip() == &quot;example&quot;<\/code>\u7684\u7ed3\u679c\u5c06\u4e3aTrue\uff0c\u8fd9\u6837\u53ef\u4ee5\u907f\u514d\u56e0\u7a7a\u767d\u5b57\u7b26\u5bfc\u81f4\u7684\u8bef\u5224\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u5224\u65ad\u5b57\u7b26\u4e32\u76f8\u7b49\u53ef\u4ee5\u4f7f\u7528\u201c==\u201d\u8fd0\u7b97\u7b26\u3001\u4f7f\u7528\u201cis\u201d\u5173\u952e\u5b57\u3001\u4f7f\u7528str.compare()\u65b9\u6cd5\u3001 [&hellip;]","protected":false},"author":3,"featured_media":922981,"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\/922974"}],"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=922974"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/922974\/revisions"}],"predecessor-version":[{"id":922983,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/922974\/revisions\/922983"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/922981"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=922974"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=922974"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=922974"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}