{"id":972624,"date":"2024-12-27T05:50:10","date_gmt":"2024-12-26T21:50:10","guid":{"rendered":""},"modified":"2024-12-27T05:50:12","modified_gmt":"2024-12-26T21:50:12","slug":"python-%e5%a6%82%e4%bd%95%e5%8c%b9%e9%85%8d%e7%a9%ba%e5%80%bc","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/972624.html","title":{"rendered":"python \u5982\u4f55\u5339\u914d\u7a7a\u503c"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24195207\/195ba9f1-2b45-4c40-8da2-187c85736c64.webp\" alt=\"python \u5982\u4f55\u5339\u914d\u7a7a\u503c\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\u5339\u914d\u7a7a\u503c\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528None\u7c7b\u578b\u3001\u68c0\u67e5\u7a7a\u5b57\u7b26\u4e32\u548c\u4f7f\u7528\u7a7a\u767d\u5b57\u7b26\u68c0\u6d4b\u51fd\u6570\u7b49\u591a\u79cd\u65b9\u6cd5\u6765\u5b9e\u73b0\u3002\u5e38\u7528\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u68c0\u67e5\u53d8\u91cf\u662f\u5426\u4e3aNone\u3001\u5229\u7528\u7a7a\u5b57\u7b26\u4e32\u7684\u5e03\u5c14\u503c\u7279\u6027\u3001\u4ee5\u53ca\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d\u7a7a\u767d\u5b57\u7b26\u7b49\u3002<\/strong>\u5176\u4e2d\uff0c\u6700\u5e38\u7528\u7684\u65b9\u6cd5\u662f\u68c0\u67e5\u53d8\u91cf\u662f\u5426\u4e3aNone\uff0c\u56e0\u4e3aNone\u662fPython\u4e2d\u8868\u793a\u7a7a\u503c\u7684\u6807\u51c6\u65b9\u5f0f\u3002\u901a\u8fc7\u4f7f\u7528<code>is<\/code>\u5173\u952e\u5b57\uff0c\u53ef\u4ee5\u76f4\u63a5\u5224\u65ad\u4e00\u4e2a\u53d8\u91cf\u662f\u5426\u662fNone\uff0c\u8fd9\u5728\u5904\u7406\u51fd\u6570\u8fd4\u56de\u503c\u6216\u8005\u521d\u59cb\u5316\u53d8\u91cf\u65f6\u975e\u5e38\u6709\u7528\u3002<\/p>\n<\/p>\n<p><p>Python\u7684None\u7c7b\u578b\u662f\u4e00\u4e2a\u7279\u6b8a\u7684\u5e38\u91cf\uff0c\u7528\u4e8e\u8868\u793a\u7a7a\u503c\u6216\u8005\u672a\u5b9a\u4e49\u7684\u503c\u3002\u5b83\u662f\u4e00\u4e2a\u5185\u7f6e\u7684\u5355\u4f8b\u5bf9\u8c61\uff0c\u901a\u5e38\u7528\u4e8e\u51fd\u6570\u8fd4\u56de\u503c\u7684\u9ed8\u8ba4\u503c\u6216\u8005\u5360\u4f4d\u7b26\u3002\u5728\u6bd4\u8f83\u65f6\uff0c\u901a\u5e38\u4f7f\u7528<code>is<\/code>\u800c\u4e0d\u662f<code>==<\/code>\uff0c\u56e0\u4e3a<code>is<\/code>\u7528\u4e8e\u5224\u65ad\u4e24\u4e2a\u53d8\u91cf\u662f\u5426\u6307\u5411\u540c\u4e00\u4e2a\u5bf9\u8c61\uff0c\u800c<code>==<\/code>\u7528\u4e8e\u5224\u65ad\u4e24\u4e2a\u53d8\u91cf\u7684\u503c\u662f\u5426\u76f8\u7b49\u3002\u4e0b\u9762\u6211\u4eec\u6765\u8be6\u7ec6\u8ba8\u8bbaPython\u4e2d\u5339\u914d\u7a7a\u503c\u7684\u591a\u79cd\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u4f7f\u7528None\u6765\u5339\u914d\u7a7a\u503c<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u7406\u89e3None\u5728Python\u4e2d\u7684\u4f5c\u7528<\/strong><\/p>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c<code>None<\/code>\u662f\u4e00\u4e2a\u7528\u4e8e\u8868\u793a\u201c\u6ca1\u6709\u503c\u201d\u7684\u7279\u6b8a\u5bf9\u8c61\u3002\u5b83\u5e38\u7528\u4e8e\u8868\u793a\u51fd\u6570\u6ca1\u6709\u8fd4\u56de\u503c\u3001\u53d8\u91cf\u672a\u521d\u59cb\u5316\u6216\u8005\u5360\u4f4d\u7b26\u3002\u56e0\u4e3a<code>None<\/code>\u662f\u4e00\u4e2a\u5355\u4f8b\u5bf9\u8c61\uff0c\u6240\u6709\u5bf9<code>None<\/code>\u7684\u6bd4\u8f83\u90fd\u5e94\u8be5\u4f7f\u7528<code>is<\/code>\u5173\u952e\u5b57\u800c\u4e0d\u662f<code>==<\/code>\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528is\u5173\u952e\u5b57\u5224\u65adNone<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528<code>is<\/code>\u5173\u952e\u5b57\u53ef\u4ee5\u6709\u6548\u5730\u5224\u65ad\u4e00\u4e2a\u53d8\u91cf\u662f\u5426\u662f<code>None<\/code>\u3002\u4f8b\u5982\uff0c\u5047\u8bbe\u4f60\u6709\u4e00\u4e2a\u51fd\u6570\u53ef\u80fd\u8fd4\u56de<code>None<\/code>\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u6765\u68c0\u67e5\u8fd4\u56de\u503c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def find_user(user_id):<\/p>\n<p>    # \u5047\u8bbe\u8fd9\u4e2a\u51fd\u6570\u4ece\u6570\u636e\u5e93\u4e2d\u67e5\u627e\u7528\u6237\uff0c\u5982\u679c\u627e\u4e0d\u5230\u5219\u8fd4\u56deNone<\/p>\n<p>    return None<\/p>\n<p>user = find_user(123)<\/p>\n<p>if user is None:<\/p>\n<p>    print(&quot;User not found&quot;)<\/p>\n<p>else:<\/p>\n<p>    print(&quot;User found&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u5f0f\u786e\u4fdd\u4e86\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u548c\u51c6\u786e\u6027\uff0c\u7279\u522b\u662f\u5728\u5904\u7406\u53ef\u80fd\u8fd4\u56de<code>None<\/code>\u7684\u51fd\u6570\u65f6\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e8c\u3001\u68c0\u67e5\u7a7a\u5b57\u7b26\u4e32<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u7a7a\u5b57\u7b26\u4e32\u4e0e\u5e03\u5c14\u503c<\/strong><\/p>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u7a7a\u5b57\u7b26\u4e32<code>&quot;&quot;<\/code>\u4f1a\u88ab\u89e3\u91ca\u4e3a<code>False<\/code>\u3002\u56e0\u6b64\uff0c\u53ef\u4ee5\u901a\u8fc7\u76f4\u63a5\u5c06\u5b57\u7b26\u4e32\u4f5c\u4e3a\u6761\u4ef6\u8fdb\u884c\u5224\u65ad\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">my_string = &quot;&quot;<\/p>\n<p>if not my_string:<\/p>\n<p>    print(&quot;The string is empty&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u7b80\u5355\u76f4\u89c2\uff0c\u9002\u7528\u4e8e\u9700\u8981\u5224\u65ad\u5b57\u7b26\u4e32\u662f\u5426\u4e3a\u7a7a\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528\u5b57\u7b26\u4e32\u65b9\u6cd5<\/strong><\/p>\n<\/p>\n<p><p>Python\u63d0\u4f9b\u4e86\u4e00\u4e9b\u5185\u7f6e\u7684\u5b57\u7b26\u4e32\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5e2e\u52a9\u68c0\u6d4b\u5b57\u7b26\u4e32\u7684\u5185\u5bb9\u3002\u4f8b\u5982\uff0c\u4f7f\u7528<code>strip()<\/code>\u65b9\u6cd5\u53bb\u9664\u5b57\u7b26\u4e32\u7684\u7a7a\u767d\uff0c\u7136\u540e\u68c0\u67e5\u7ed3\u679c\u662f\u5426\u4e3a\u7a7a\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">my_string = &quot;   &quot;<\/p>\n<p>if not my_string.strip():<\/p>\n<p>    print(&quot;The string cont<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>ns only whitespace&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u5728\u9700\u8981\u5224\u65ad\u5b57\u7b26\u4e32\u662f\u5426\u4ec5\u5305\u542b\u7a7a\u767d\u5b57\u7b26\u65f6\u7279\u522b\u6709\u7528\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e09\u3001\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d\u7a7a\u503c<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4f7f\u7528re\u6a21\u5757<\/strong><\/p>\n<\/p>\n<p><p>Python\u7684<code>re<\/code>\u6a21\u5757\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u529f\u80fd\uff0c\u53ef\u4ee5\u7528\u6765\u5339\u914d\u590d\u6742\u7684\u5b57\u7b26\u4e32\u6a21\u5f0f\u3002\u5bf9\u4e8e\u7a7a\u503c\u5339\u914d\uff0c\u6b63\u5219\u8868\u8fbe\u5f0f\u53ef\u4ee5\u68c0\u6d4b\u7a7a\u5b57\u7b26\u4e32\u6216\u4ec5\u5305\u542b\u7a7a\u767d\u5b57\u7b26\u7684\u5b57\u7b26\u4e32\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import re<\/p>\n<p>def is_empty_or_whitespace(s):<\/p>\n<p>    return re.fullmatch(r&#39;\\s*&#39;, s) is not None<\/p>\n<p>print(is_empty_or_whitespace(&quot;&quot;))        # True<\/p>\n<p>print(is_empty_or_whitespace(&quot;   &quot;))     # True<\/p>\n<p>print(is_empty_or_whitespace(&quot;abc&quot;))     # False<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u53ef\u4ee5\u7075\u6d3b\u5730\u5339\u914d\u5b57\u7b26\u4e32\u7684\u591a\u79cd\u5f62\u5f0f\uff0c\u4f46\u5728\u7b80\u5355\u7684\u7a7a\u503c\u68c0\u67e5\u4e2d\u53ef\u80fd\u663e\u5f97\u8fc7\u4e8e\u590d\u6742\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u590d\u6742\u5339\u914d\u573a\u666f<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u573a\u666f\u4e0b\uff0c\u53ef\u80fd\u9700\u8981\u5339\u914d\u66f4\u590d\u6742\u7684\u7a7a\u503c\u6a21\u5f0f\u3002\u4f8b\u5982\uff0c\u68c0\u67e5\u4e00\u4e2a\u5b57\u7b26\u4e32\u662f\u5426\u4ec5\u5305\u542b\u67d0\u4e9b\u7279\u5b9a\u7684\u7a7a\u767d\u5b57\u7b26\uff0c\u6216\u8005\u5728\u5904\u7406\u6587\u672c\u89e3\u6790\u65f6\uff0c\u9700\u8981\u5ffd\u7565\u7279\u5b9a\u7684\u7a7a\u767d\u6a21\u5f0f\u3002\u6b63\u5219\u8868\u8fbe\u5f0f\u63d0\u4f9b\u4e86\u8fd9\u79cd\u7075\u6d3b\u6027\uff0c\u53ef\u4ee5\u6839\u636e\u9700\u8981\u8bbe\u8ba1\u590d\u6742\u7684\u5339\u914d\u89c4\u5219\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u56db\u3001\u4f7f\u7528\u7a7a\u767d\u5b57\u7b26\u68c0\u6d4b\u51fd\u6570<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4f7f\u7528str\u7c7b\u65b9\u6cd5<\/strong><\/p>\n<\/p>\n<p><p>Python\u7684<code>str<\/code>\u7c7b\u63d0\u4f9b\u4e86\u4e00\u4e9b\u65b9\u6cd5\uff0c\u53ef\u4ee5\u76f4\u63a5\u7528\u4e8e\u68c0\u6d4b\u5b57\u7b26\u4e32\u4e2d\u7684\u7a7a\u767d\u5b57\u7b26\uff0c\u4f8b\u5982<code>isspace()<\/code>\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">my_string = &quot;   &quot;<\/p>\n<p>if my_string.isspace():<\/p>\n<p>    print(&quot;The string contains only whitespace&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><code>isspace()<\/code>\u65b9\u6cd5\u8fd4\u56de<code>True<\/code>\u5982\u679c\u5b57\u7b26\u4e32\u53ea\u5305\u542b\u7a7a\u767d\u5b57\u7b26\uff0c\u8fd9\u5728\u9700\u8981\u5224\u65ad\u5b57\u7b26\u4e32\u662f\u5426\u5168\u4e3a\u7a7a\u767d\u65f6\u975e\u5e38\u6709\u7528\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u7ed3\u5408\u5176\u4ed6\u65b9\u6cd5<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u53ef\u80fd\u9700\u8981\u7ed3\u5408\u5176\u4ed6\u65b9\u6cd5\u6765\u5b9e\u73b0\u66f4\u590d\u6742\u7684\u7a7a\u503c\u68c0\u6d4b\u3002\u4f8b\u5982\uff0c\u7ed3\u5408<code>strip()<\/code>\u65b9\u6cd5\u548c<code>isspace()<\/code>\u65b9\u6cd5\uff0c\u53ef\u4ee5\u786e\u4fdd\u5b57\u7b26\u4e32\u4e0d\u4ec5\u88ab\u7a7a\u767d\u5b57\u7b26\u586b\u5145\uff0c\u8fd8\u6392\u9664\u4e86\u5176\u4ed6\u6f5c\u5728\u7684\u975e\u53ef\u89c1\u5b57\u7b26\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e94\u3001\u5904\u7406\u6570\u636e\u7ed3\u6784\u4e2d\u7684\u7a7a\u503c<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5217\u8868\u548c\u5b57\u5178\u4e2d\u7684\u7a7a\u503c<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u5904\u7406\u6570\u636e\u7ed3\u6784\uff08\u5982\u5217\u8868\u3001\u5b57\u5178\uff09\u65f6\uff0c\u4e5f\u9700\u8981\u8003\u8651\u7a7a\u503c\u7684\u95ee\u9898\u3002\u4f8b\u5982\uff0c\u4e00\u4e2a\u5217\u8868\u53ef\u80fd\u5305\u542b<code>None<\/code>\uff0c\u6216\u8005\u4e00\u4e2a\u5b57\u5178\u53ef\u80fd\u6709\u7a7a\u5b57\u7b26\u4e32\u4f5c\u4e3a\u503c\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u53ef\u4ee5\u901a\u8fc7\u904d\u5386\u6570\u636e\u7ed3\u6784\u6765\u68c0\u67e5\u7a7a\u503c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">my_list = [None, &quot;&quot;, &quot;abc&quot;]<\/p>\n<p>for item in my_list:<\/p>\n<p>    if item is None or item == &quot;&quot;:<\/p>\n<p>        print(&quot;Found an empty value&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528\u5217\u8868\u89e3\u6790\u548c\u8fc7\u6ee4<\/strong><\/p>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528\u5217\u8868\u89e3\u6790\u548c\u8fc7\u6ee4\u6280\u672f\u6765\u79fb\u9664\u6570\u636e\u7ed3\u6784\u4e2d\u7684\u7a7a\u503c\u3002\u8fd9\u5bf9\u4e8e\u6e05\u7406\u6570\u636e\u548c\u51c6\u5907\u6570\u636e\u5206\u6790\u7279\u522b\u6709\u7528\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">my_list = [None, &quot;&quot;, &quot;abc&quot;, &quot;   &quot;]<\/p>\n<p>cleaned_list = [item for item in my_list if item and not item.isspace()]<\/p>\n<p>print(cleaned_list)  # \u8f93\u51fa: [&#39;abc&#39;]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u9ad8\u6548\u4e14\u7b80\u6d01\uff0c\u9002\u7528\u4e8e\u9700\u8981\u6279\u91cf\u5904\u7406\u6570\u636e\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u603b\u7ed3\u6765\u8bf4\uff0cPython\u63d0\u4f9b\u4e86\u591a\u79cd\u65b9\u6cd5\u6765\u5339\u914d\u548c\u5904\u7406\u7a7a\u503c\uff0c\u5305\u62ec\u4f7f\u7528<code>None<\/code>\u3001\u68c0\u67e5\u7a7a\u5b57\u7b26\u4e32\u3001\u5229\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u4ee5\u53ca\u68c0\u6d4b\u7a7a\u767d\u5b57\u7b26\u7684\u65b9\u6cd5\u3002\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u53d6\u51b3\u4e8e\u5177\u4f53\u7684\u5e94\u7528\u573a\u666f\u548c\u6570\u636e\u7c7b\u578b\u3002\u5728\u5b9e\u8df5\u4e2d\uff0c\u5408\u7406\u5730\u9009\u62e9\u548c\u7ec4\u5408\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u53ef\u4ee5\u6709\u6548\u5730\u63d0\u9ad8\u4ee3\u7801\u7684\u5065\u58ee\u6027\u548c\u53ef\u8bfb\u6027\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u68c0\u6d4b\u7a7a\u503c\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u65b9\u6cd5\u6765\u68c0\u6d4b\u7a7a\u503c\u3002\u6700\u5e38\u7528\u7684\u65b9\u6cd5\u662f\u4f7f\u7528<code>None<\/code>\u5173\u952e\u5b57\u6765\u68c0\u67e5\u4e00\u4e2a\u53d8\u91cf\u662f\u5426\u4e3a\u7a7a\u3002\u6b64\u5916\uff0c\u53ef\u4ee5\u4f7f\u7528<code>if not variable<\/code>\u7684\u5f62\u5f0f\u6765\u5224\u65ad\u4e00\u4e2a\u53d8\u91cf\u662f\u5426\u4e3a\u5047\u503c\uff0c\u5305\u62ec<code>None<\/code>\u3001\u7a7a\u5b57\u7b26\u4e32\u3001\u7a7a\u5217\u8868\u7b49\u3002\u5bf9\u4e8ePandas\u5e93\u4e2d\u7684\u6570\u636e\u6846\uff0c\u53ef\u4ee5\u4f7f\u7528<code>isnull()<\/code>\u6216<code>isna()<\/code>\u51fd\u6570\u6765\u68c0\u67e5\u6570\u636e\u4e2d\u7684\u7a7a\u503c\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u5982\u4f55\u5904\u7406\u7a7a\u503c\uff1f<\/strong><br \/>\u5904\u7406\u7a7a\u503c\u7684\u65b9\u6cd5\u6709\u5f88\u591a\uff0c\u5177\u4f53\u53d6\u51b3\u4e8e\u60a8\u7684\u9700\u6c42\u3002\u5982\u679c\u60a8\u4f7f\u7528\u7684\u662f\u5217\u8868\u6216\u5b57\u5178\uff0c\u53ef\u4ee5\u9009\u62e9\u5220\u9664\u7a7a\u503c\u5143\u7d20\u6216\u8005\u7528\u9ed8\u8ba4\u503c\u66ff\u6362\u5b83\u4eec\u3002\u5728Pandas\u6570\u636e\u6846\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>fillna()<\/code>\u65b9\u6cd5\u6765\u586b\u5145\u7a7a\u503c\uff0c\u6216\u8005\u4f7f\u7528<code>dropna()<\/code>\u65b9\u6cd5\u6765\u5220\u9664\u5305\u542b\u7a7a\u503c\u7684\u884c\u6216\u5217\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728\u6b63\u5219\u8868\u8fbe\u5f0f\u4e2d\u5339\u914d\u7a7a\u503c\uff1f<\/strong><br \/>\u5728Python\u4e2d\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7\u6a21\u5f0f\u6765\u5339\u914d\u7a7a\u503c\u3002\u6bd4\u5982\uff0c\u4f7f\u7528<code>^$<\/code>\u6a21\u5f0f\u53ef\u4ee5\u5339\u914d\u7a7a\u5b57\u7b26\u4e32\u3002\u5982\u679c\u60f3\u8981\u5339\u914d\u5305\u542b\u7a7a\u683c\u7684\u5b57\u7b26\u4e32\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528<code>^\\s*$<\/code>\u3002\u901a\u8fc7<code>re<\/code>\u6a21\u5757\uff0c\u60a8\u53ef\u4ee5\u8f7b\u677e\u5730\u5e94\u7528\u8fd9\u4e9b\u6a21\u5f0f\u6765\u67e5\u627e\u7a7a\u503c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u5339\u914d\u7a7a\u503c\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528None\u7c7b\u578b\u3001\u68c0\u67e5\u7a7a\u5b57\u7b26\u4e32\u548c\u4f7f\u7528\u7a7a\u767d\u5b57\u7b26\u68c0\u6d4b\u51fd\u6570\u7b49\u591a\u79cd\u65b9\u6cd5\u6765\u5b9e\u73b0\u3002\u5e38\u7528\u7684\u65b9 [&hellip;]","protected":false},"author":3,"featured_media":972629,"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\/972624"}],"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=972624"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/972624\/revisions"}],"predecessor-version":[{"id":972631,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/972624\/revisions\/972631"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/972629"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=972624"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=972624"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=972624"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}