{"id":1068730,"date":"2024-12-31T16:45:57","date_gmt":"2024-12-31T08:45:57","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1068730.html"},"modified":"2024-12-31T16:46:00","modified_gmt":"2024-12-31T08:46:00","slug":"python%e5%a6%82%e4%bd%95%e4%bb%8e%e5%ad%97%e7%ac%a6%e4%b8%b2%e4%b8%ad%e6%8f%90%e5%8f%96%e6%95%b0%e5%ad%97","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1068730.html","title":{"rendered":"python\u5982\u4f55\u4ece\u5b57\u7b26\u4e32\u4e2d\u63d0\u53d6\u6570\u5b57"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2024\/12\/9272a89e-7405-4075-990e-df469cb90e67.webp?x-oss-process=image\/auto-orient,1\/format,webp\" alt=\"python\u5982\u4f55\u4ece\u5b57\u7b26\u4e32\u4e2d\u63d0\u53d6\u6570\u5b57\" \/><\/p>\n<p><p> <strong>\u8981\u4ecePython\u5b57\u7b26\u4e32\u4e2d\u63d0\u53d6\u6570\u5b57\uff0c\u53ef\u4ee5\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u3001\u5b57\u7b26\u4e32\u65b9\u6cd5\u3001\u5217\u8868\u89e3\u6790\u7b49\u65b9\u6cd5\u3002\u6700\u5e38\u7528\u4e14\u5f3a\u5927\u7684\u65b9\u6cd5\u662f\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u51e0\u79cd\u65b9\u6cd5\uff0c\u91cd\u70b9\u8bb2\u89e3\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u4f7f\u7528\u3002<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u65f6\uff0c\u901a\u8fc7<code>re<\/code>\u6a21\u5757\uff0c\u6211\u4eec\u53ef\u4ee5\u8f7b\u677e\u627e\u5230\u5b57\u7b26\u4e32\u4e2d\u7684\u6570\u5b57\u3002\u6b63\u5219\u8868\u8fbe\u5f0f\u5f3a\u5927\u4e14\u7075\u6d3b\uff0c\u9002\u7528\u4e8e\u5404\u79cd\u590d\u6742\u7684\u5339\u914d\u9700\u6c42\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u4ee5\u53ca\u5176\u4ed6\u65b9\u6cd5\u4ece\u5b57\u7b26\u4e32\u4e2d\u63d0\u53d6\u6570\u5b57\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u6b63\u5219\u8868\u8fbe\u5f0f\u63d0\u53d6\u6570\u5b57<\/h3>\n<\/p>\n<p><p>\u6b63\u5219\u8868\u8fbe\u5f0f\uff08Regular Expression\uff0c\u7b80\u79f0regex\uff09\u662f\u4e00\u79cd\u63cf\u8ff0\u5b57\u7b26\u6a21\u5f0f\u7684\u7279\u6b8a\u8bed\u6cd5\uff0c\u7528\u4e8e\u67e5\u627e\u548c\u5339\u914d\u5b57\u7b26\u4e32\u4e2d\u7684\u5b50\u4e32\u3002Python\u901a\u8fc7<code>re<\/code>\u6a21\u5757\u63d0\u4f9b\u5bf9\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u652f\u6301\u3002<\/p>\n<\/p>\n<p><h4>1. \u5b89\u88c5\u548c\u5bfc\u5165<code>re<\/code>\u6a21\u5757<\/h4>\n<\/p>\n<p><p><code>re<\/code>\u6a21\u5757\u662fPython\u7684\u5185\u7f6e\u6a21\u5757\uff0c\u65e0\u9700\u5b89\u88c5\uff0c\u53ea\u9700\u5bfc\u5165\u5373\u53ef\u4f7f\u7528\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import re<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u4f7f\u7528<code>re.findall()<\/code>\u65b9\u6cd5<\/h4>\n<\/p>\n<p><p><code>re.findall(pattern, string)<\/code>\u65b9\u6cd5\u7528\u4e8e\u5728\u5b57\u7b26\u4e32\u4e2d\u67e5\u627e\u6240\u6709\u4e0e\u6a21\u5f0f\u5339\u914d\u7684\u5b50\u4e32\uff0c\u5e76\u4ee5\u5217\u8868\u5f62\u5f0f\u8fd4\u56de\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import re<\/p>\n<h2><strong>\u793a\u4f8b\u5b57\u7b26\u4e32<\/strong><\/h2>\n<p>text = &quot;The price is 100 dollars, and the discount is 20%.&quot;<\/p>\n<h2><strong>\u6b63\u5219\u8868\u8fbe\u5f0f\u6a21\u5f0f<\/strong><\/h2>\n<p>pattern = r&#39;\\d+&#39;<\/p>\n<h2><strong>\u63d0\u53d6\u6570\u5b57<\/strong><\/h2>\n<p>numbers = re.findall(pattern, text)<\/p>\n<p>print(numbers)  # \u8f93\u51fa\uff1a[&#39;100&#39;, &#39;20&#39;]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u8be6\u7ec6\u63cf\u8ff0\uff1a<\/strong><\/p>\n<\/p>\n<ul>\n<li><code>\\d<\/code>\u8868\u793a\u5339\u914d\u4e00\u4e2a\u6570\u5b57\u5b57\u7b26\u3002<\/li>\n<li><code>+<\/code>\u8868\u793a\u5339\u914d\u524d\u9762\u7684\u5b57\u7b26\u4e00\u6b21\u6216\u591a\u6b21\u3002<\/li>\n<\/ul>\n<p><h3>\u4e8c\u3001\u4f7f\u7528\u5b57\u7b26\u4e32\u65b9\u6cd5\u63d0\u53d6\u6570\u5b57<\/h3>\n<\/p>\n<p><p>Python\u7684\u5b57\u7b26\u4e32\u65b9\u6cd5\u4e5f\u53ef\u4ee5\u7528\u4e8e\u63d0\u53d6\u6570\u5b57\uff0c\u5c3d\u7ba1\u4e0d\u5982\u6b63\u5219\u8868\u8fbe\u5f0f\u7075\u6d3b\uff0c\u4f46\u5728\u7b80\u5355\u573a\u666f\u4e0b\u540c\u6837\u6709\u6548\u3002<\/p>\n<\/p>\n<p><h4>1. \u4f7f\u7528\u5b57\u7b26\u4e32\u904d\u5386\u548c\u6761\u4ef6\u5224\u65ad<\/h4>\n<\/p>\n<p><p>\u901a\u8fc7\u904d\u5386\u5b57\u7b26\u4e32\u4e2d\u7684\u6bcf\u4e2a\u5b57\u7b26\uff0c\u5224\u65ad\u5176\u662f\u5426\u4e3a\u6570\u5b57\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u793a\u4f8b\u5b57\u7b26\u4e32<\/p>\n<p>text = &quot;The price is 100 dollars, and the discount is 20%.&quot;<\/p>\n<h2><strong>\u5b58\u50a8\u6570\u5b57<\/strong><\/h2>\n<p>numbers = []<\/p>\n<h2><strong>\u904d\u5386\u5b57\u7b26\u4e32<\/strong><\/h2>\n<p>for char in text:<\/p>\n<p>    if char.isdigit():<\/p>\n<p>        numbers.append(char)<\/p>\n<p>print(numbers)  # \u8f93\u51fa\uff1a[&#39;1&#39;, &#39;0&#39;, &#39;0&#39;, &#39;2&#39;, &#39;0&#39;]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u8be6\u7ec6\u63cf\u8ff0\uff1a<\/strong><\/p>\n<\/p>\n<ul>\n<li><code>char.isdigit()<\/code>\u65b9\u6cd5\u7528\u4e8e\u5224\u65ad\u5b57\u7b26\u662f\u5426\u4e3a\u6570\u5b57\u3002<\/li>\n<\/ul>\n<p><h4>2. \u4f7f\u7528\u5217\u8868\u89e3\u6790<\/h4>\n<\/p>\n<p><p>\u5217\u8868\u89e3\u6790\u662f\u4e00\u79cd\u7b80\u6d01\u4f18\u96c5\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5c06\u904d\u5386\u548c\u6761\u4ef6\u5224\u65ad\u7ed3\u5408\u5728\u4e00\u884c\u4ee3\u7801\u4e2d\u5b8c\u6210\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u793a\u4f8b\u5b57\u7b26\u4e32<\/p>\n<p>text = &quot;The price is 100 dollars, and the discount is 20%.&quot;<\/p>\n<h2><strong>\u63d0\u53d6\u6570\u5b57<\/strong><\/h2>\n<p>numbers = [char for char in text if char.isdigit()]<\/p>\n<p>print(numbers)  # \u8f93\u51fa\uff1a[&#39;1&#39;, &#39;0&#39;, &#39;0&#39;, &#39;2&#39;, &#39;0&#39;]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u8be6\u7ec6\u63cf\u8ff0\uff1a<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u5217\u8868\u89e3\u6790\u4f7f\u4ee3\u7801\u66f4\u7b80\u6d01\uff0c\u53ef\u8bfb\u6027\u66f4\u9ad8\u3002<\/li>\n<\/ul>\n<p><h3>\u4e09\u3001\u7ed3\u5408\u65b9\u6cd5\u63d0\u53d6\u6570\u5b57<\/h3>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u5e38\u5e38\u9700\u8981\u63d0\u53d6\u5b8c\u6574\u7684\u6570\u5b57\uff08\u800c\u4e0d\u662f\u5355\u4e2a\u5b57\u7b26\uff09\uff0c\u8fd9\u65f6\u53ef\u4ee5\u7ed3\u5408\u4f7f\u7528\u5b57\u7b26\u4e32\u65b9\u6cd5\u548c\u6b63\u5219\u8868\u8fbe\u5f0f\u3002<\/p>\n<\/p>\n<p><h4>1. \u63d0\u53d6\u5b8c\u6574\u6570\u5b57<\/h4>\n<\/p>\n<p><p>\u901a\u8fc7\u5b57\u7b26\u4e32\u62c6\u5206\u548c\u6761\u4ef6\u5224\u65ad\uff0c\u63d0\u53d6\u5b8c\u6574\u7684\u6570\u5b57\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u793a\u4f8b\u5b57\u7b26\u4e32<\/p>\n<p>text = &quot;The price is 100 dollars, and the discount is 20%.&quot;<\/p>\n<h2><strong>\u62c6\u5206\u5b57\u7b26\u4e32<\/strong><\/h2>\n<p>parts = text.split()<\/p>\n<h2><strong>\u5b58\u50a8\u6570\u5b57<\/strong><\/h2>\n<p>numbers = []<\/p>\n<h2><strong>\u904d\u5386\u6bcf\u4e2a\u90e8\u5206<\/strong><\/h2>\n<p>for part in parts:<\/p>\n<p>    if part.isdigit():<\/p>\n<p>        numbers.append(part)<\/p>\n<p>print(numbers)  # \u8f93\u51fa\uff1a[&#39;100&#39;, &#39;20&#39;]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u8be6\u7ec6\u63cf\u8ff0\uff1a<\/strong><\/p>\n<\/p>\n<ul>\n<li><code>split()<\/code>\u65b9\u6cd5\u5c06\u5b57\u7b26\u4e32\u62c6\u5206\u4e3a\u5355\u8bcd\u5217\u8868\u3002<\/li>\n<li><code>part.isdigit()<\/code>\u5224\u65ad\u6bcf\u4e2a\u5355\u8bcd\u662f\u5426\u4e3a\u6570\u5b57\u3002<\/li>\n<\/ul>\n<p><h3>\u56db\u3001\u4f7f\u7528\u66f4\u590d\u6742\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u6a21\u5f0f<\/h3>\n<\/p>\n<p><p>\u5728\u5904\u7406\u66f4\u590d\u6742\u7684\u5b57\u7b26\u4e32\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u66f4\u590d\u6742\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u6a21\u5f0f\u3002\u4f8b\u5982\uff0c\u63d0\u53d6\u5305\u542b\u5c0f\u6570\u70b9\u7684\u6570\u5b57\u3002<\/p>\n<\/p>\n<p><h4>1. \u63d0\u53d6\u5305\u542b\u5c0f\u6570\u70b9\u7684\u6570\u5b57<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">import re<\/p>\n<h2><strong>\u793a\u4f8b\u5b57\u7b26\u4e32<\/strong><\/h2>\n<p>text = &quot;The price is 100.50 dollars, and the discount is 20.5%.&quot;<\/p>\n<h2><strong>\u6b63\u5219\u8868\u8fbe\u5f0f\u6a21\u5f0f<\/strong><\/h2>\n<p>pattern = r&#39;\\d+\\.?\\d*&#39;<\/p>\n<h2><strong>\u63d0\u53d6\u6570\u5b57<\/strong><\/h2>\n<p>numbers = re.findall(pattern, text)<\/p>\n<p>print(numbers)  # \u8f93\u51fa\uff1a[&#39;100.50&#39;, &#39;20.5&#39;]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u8be6\u7ec6\u63cf\u8ff0\uff1a<\/strong><\/p>\n<\/p>\n<ul>\n<li><code>\\d+<\/code>\u5339\u914d\u4e00\u4e2a\u6216\u591a\u4e2a\u6570\u5b57\u3002<\/li>\n<li><code>\\.?<\/code>\u5339\u914d\u96f6\u4e2a\u6216\u4e00\u4e2a\u5c0f\u6570\u70b9\u3002<\/li>\n<li><code>\\d*<\/code>\u5339\u914d\u96f6\u4e2a\u6216\u591a\u4e2a\u6570\u5b57\u3002<\/li>\n<\/ul>\n<p><h3>\u4e94\u3001\u4ece\u5b57\u7b26\u4e32\u4e2d\u63d0\u53d6\u6570\u5b57\u5e76\u8f6c\u6362\u4e3a\u6574\u6570\u6216\u6d6e\u70b9\u6570<\/h3>\n<\/p>\n<p><p>\u6709\u65f6\u63d0\u53d6\u6570\u5b57\u540e\u9700\u8981\u5c06\u5176\u8f6c\u6362\u4e3a\u6574\u6570\u6216\u6d6e\u70b9\u6570\uff0c\u4ee5\u4fbf\u8fdb\u884c\u6570\u5b66\u8fd0\u7b97\u3002<\/p>\n<\/p>\n<p><h4>1. \u63d0\u53d6\u5e76\u8f6c\u6362\u4e3a\u6574\u6570<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">import re<\/p>\n<h2><strong>\u793a\u4f8b\u5b57\u7b26\u4e32<\/strong><\/h2>\n<p>text = &quot;The price is 100 dollars, and the discount is 20%.&quot;<\/p>\n<h2><strong>\u63d0\u53d6\u6570\u5b57<\/strong><\/h2>\n<p>pattern = r&#39;\\d+&#39;<\/p>\n<p>numbers = re.findall(pattern, text)<\/p>\n<h2><strong>\u8f6c\u6362\u4e3a\u6574\u6570<\/strong><\/h2>\n<p>int_numbers = list(map(int, numbers))<\/p>\n<p>print(int_numbers)  # \u8f93\u51fa\uff1a[&#39;100&#39;, &#39;20&#39;]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u8be6\u7ec6\u63cf\u8ff0\uff1a<\/strong><\/p>\n<\/p>\n<ul>\n<li><code>map(int, numbers)<\/code>\u5c06\u63d0\u53d6\u7684\u6570\u5b57\u5217\u8868\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u8f6c\u6362\u4e3a\u6574\u6570\u3002<\/li>\n<\/ul>\n<p><h4>2. \u63d0\u53d6\u5e76\u8f6c\u6362\u4e3a\u6d6e\u70b9\u6570<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">import re<\/p>\n<h2><strong>\u793a\u4f8b\u5b57\u7b26\u4e32<\/strong><\/h2>\n<p>text = &quot;The price is 100.50 dollars, and the discount is 20.5%.&quot;<\/p>\n<h2><strong>\u63d0\u53d6\u6570\u5b57<\/strong><\/h2>\n<p>pattern = r&#39;\\d+\\.?\\d*&#39;<\/p>\n<p>numbers = re.findall(pattern, text)<\/p>\n<h2><strong>\u8f6c\u6362\u4e3a\u6d6e\u70b9\u6570<\/strong><\/h2>\n<p>float_numbers = list(map(float, numbers))<\/p>\n<p>print(float_numbers)  # \u8f93\u51fa\uff1a[&#39;100.50&#39;, &#39;20.5&#39;]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u8be6\u7ec6\u63cf\u8ff0\uff1a<\/strong><\/p>\n<\/p>\n<ul>\n<li><code>map(float, numbers)<\/code>\u5c06\u63d0\u53d6\u7684\u6570\u5b57\u5217\u8868\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u8f6c\u6362\u4e3a\u6d6e\u70b9\u6570\u3002<\/li>\n<\/ul>\n<p><h3>\u516d\u3001\u4ece\u5b57\u7b26\u4e32\u4e2d\u63d0\u53d6\u8d1f\u6570<\/h3>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u573a\u666f\u4e2d\uff0c\u9700\u8981\u4ece\u5b57\u7b26\u4e32\u4e2d\u63d0\u53d6\u8d1f\u6570\u3002\u6b64\u65f6\u53ef\u4ee5\u4f7f\u7528\u5e26\u6709\u8d1f\u53f7\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u6a21\u5f0f\u3002<\/p>\n<\/p>\n<p><h4>1. \u63d0\u53d6\u8d1f\u6570<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">import re<\/p>\n<h2><strong>\u793a\u4f8b\u5b57\u7b26\u4e32<\/strong><\/h2>\n<p>text = &quot;The temperature is -5 degrees, and the wind speed is -20 km\/h.&quot;<\/p>\n<h2><strong>\u6b63\u5219\u8868\u8fbe\u5f0f\u6a21\u5f0f<\/strong><\/h2>\n<p>pattern = r&#39;-?\\d+\\.?\\d*&#39;<\/p>\n<h2><strong>\u63d0\u53d6\u6570\u5b57<\/strong><\/h2>\n<p>numbers = re.findall(pattern, text)<\/p>\n<p>print(numbers)  # \u8f93\u51fa\uff1a[&#39;-5&#39;, &#39;-20&#39;]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u8be6\u7ec6\u63cf\u8ff0\uff1a<\/strong><\/p>\n<\/p>\n<ul>\n<li><code>-?<\/code>\u5339\u914d\u96f6\u4e2a\u6216\u4e00\u4e2a\u8d1f\u53f7\u3002<\/li>\n<li>\u5176\u4ed6\u90e8\u5206\u4e0e\u524d\u9762\u7c7b\u4f3c\u3002<\/li>\n<\/ul>\n<p><h3>\u4e03\u3001\u7ed3\u8bba<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u51e0\u79cd\u65b9\u6cd5\uff0c\u53ef\u4ee5\u8f7b\u677e\u4ecePython\u5b57\u7b26\u4e32\u4e2d\u63d0\u53d6\u6570\u5b57\u3002\u6b63\u5219\u8868\u8fbe\u5f0f\u65b9\u6cd5\u6700\u4e3a\u5f3a\u5927\uff0c\u9002\u7528\u4e8e\u5404\u79cd\u590d\u6742\u7684\u5339\u914d\u9700\u6c42\uff1b\u5b57\u7b26\u4e32\u65b9\u6cd5\u548c\u5217\u8868\u89e3\u6790\u9002\u7528\u4e8e\u7b80\u5355\u573a\u666f\uff1b\u7ed3\u5408\u65b9\u6cd5\u53ef\u4ee5\u63d0\u53d6\u5b8c\u6574\u6570\u5b57\uff1b\u66f4\u590d\u6742\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u6a21\u5f0f\u53ef\u4ee5\u5904\u7406\u5c0f\u6570\u548c\u8d1f\u6570\u3002\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u9ad8\u6548\u5730\u5b8c\u6210\u4efb\u52a1\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u63d0\u53d6\u5b57\u7b26\u4e32\u4e2d\u7684\u6240\u6709\u6570\u5b57\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u6765\u63d0\u53d6\u5b57\u7b26\u4e32\u4e2d\u7684\u6240\u6709\u6570\u5b57\u3002\u4f7f\u7528<code>re<\/code>\u6a21\u5757\u7684<code>findall<\/code>\u65b9\u6cd5\uff0c\u53ef\u4ee5\u8f7b\u677e\u5b9e\u73b0\u3002\u4f8b\u5982\uff0c<code>re.findall(r&#39;\\d+&#39;, string)<\/code>\u53ef\u4ee5\u8fd4\u56de\u5b57\u7b26\u4e32\u4e2d\u6240\u6709\u7684\u6570\u5b57\u3002\u4f60\u53ef\u4ee5\u5c06\u8fd9\u4e9b\u6570\u5b57\u5b58\u50a8\u5728\u5217\u8868\u4e2d\uff0c\u4ee5\u4fbf\u540e\u7eed\u5904\u7406\u3002<\/p>\n<p><strong>\u63d0\u53d6\u6570\u5b57\u65f6\u5982\u4f55\u5904\u7406\u5c0f\u6570\u548c\u8d1f\u6570\uff1f<\/strong><br \/>\u5982\u679c\u9700\u8981\u63d0\u53d6\u5c0f\u6570\u548c\u8d1f\u6570\uff0c\u53ef\u4ee5\u7a0d\u5fae\u4fee\u6539\u6b63\u5219\u8868\u8fbe\u5f0f\u3002\u5bf9\u4e8e\u5c0f\u6570\uff0c\u53ef\u4ee5\u4f7f\u7528<code>r&#39;-?\\d+(\\.\\d+)?&#39;<\/code>\uff0c\u8fd9\u4e2a\u8868\u8fbe\u5f0f\u5c06\u5339\u914d\u53ef\u80fd\u5e26\u6709\u8d1f\u53f7\u7684\u6574\u6570\u548c\u5c0f\u6570\u3002\u4f7f\u7528\u8fd9\u79cd\u65b9\u5f0f\uff0c\u4f60\u53ef\u4ee5\u786e\u4fdd\u63d0\u53d6\u5230\u7684\u6570\u5b57\u5305\u542b\u66f4\u590d\u6742\u7684\u683c\u5f0f\u3002<\/p>\n<p><strong>\u5982\u4f55\u5c06\u63d0\u53d6\u5230\u7684\u6570\u5b57\u8f6c\u6362\u4e3a\u6574\u6570\u6216\u6d6e\u70b9\u6570\uff1f<\/strong><br \/>\u63d0\u53d6\u5230\u7684\u6570\u5b57\u901a\u5e38\u4ee5\u5b57\u7b26\u4e32\u5f62\u5f0f\u5b58\u5728\uff0c\u82e5\u9700\u8981\u5c06\u5b83\u4eec\u8f6c\u6362\u4e3a\u6574\u6570\u6216\u6d6e\u70b9\u6570\uff0c\u53ef\u4ee5\u4f7f\u7528<code>int()<\/code>\u6216<code>float()<\/code>\u51fd\u6570\u8fdb\u884c\u8f6c\u6362\u3002\u4f8b\u5982\uff0c<code>int(num)<\/code>\u5c06\u5b57\u7b26\u4e32\u5f62\u5f0f\u7684\u6570\u5b57\u8f6c\u6362\u4e3a\u6574\u6570\uff0c\u800c<code>float(num)<\/code>\u5219\u5c06\u5176\u8f6c\u6362\u4e3a\u6d6e\u70b9\u6570\u3002\u53ef\u4ee5\u5728\u63d0\u53d6\u540e\u904d\u5386\u6570\u5b57\u5217\u8868\u8fdb\u884c\u8f6c\u6362\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u8981\u4ecePython\u5b57\u7b26\u4e32\u4e2d\u63d0\u53d6\u6570\u5b57\uff0c\u53ef\u4ee5\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u3001\u5b57\u7b26\u4e32\u65b9\u6cd5\u3001\u5217\u8868\u89e3\u6790\u7b49\u65b9\u6cd5\u3002\u6700\u5e38\u7528\u4e14\u5f3a\u5927\u7684\u65b9\u6cd5\u662f\u4f7f\u7528\u6b63\u5219 [&hellip;]","protected":false},"author":3,"featured_media":1068737,"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\/1068730"}],"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=1068730"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1068730\/revisions"}],"predecessor-version":[{"id":1068743,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1068730\/revisions\/1068743"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1068737"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1068730"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1068730"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1068730"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}