{"id":1073523,"date":"2025-01-08T11:26:24","date_gmt":"2025-01-08T03:26:24","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1073523.html"},"modified":"2025-01-08T11:26:26","modified_gmt":"2025-01-08T03:26:26","slug":"python%e5%a6%82%e4%bd%95%e6%8a%8a%e5%ad%97%e7%ac%a6%e4%b8%b2%e5%8c%96%e4%b8%bafloat-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1073523.html","title":{"rendered":"python\u5982\u4f55\u628a\u5b57\u7b26\u4e32\u5316\u4e3afloat"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25103421\/2f9295bd-2a22-43a1-b309-67fa7dc6fd18.webp\" alt=\"python\u5982\u4f55\u628a\u5b57\u7b26\u4e32\u5316\u4e3afloat\" \/><\/p>\n<p><p> <strong>Python\u5c06\u5b57\u7b26\u4e32\u8f6c\u5316\u4e3afloat\u7684\u65b9\u6cd5\u6709\uff1a\u4f7f\u7528float()\u51fd\u6570\u3001\u5904\u7406\u5f02\u5e38\u60c5\u51b5\u3001\u53bb\u9664\u5b57\u7b26\u4e32\u4e2d\u7684\u975e\u6570\u5b57\u5b57\u7b26\u3002<\/strong><\/p>\n<\/p>\n<p><p>\u6700\u5e38\u7528\u7684\u65b9\u6cd5\u662f\u4f7f\u7528Python\u5185\u7f6e\u7684<code>float()<\/code>\u51fd\u6570\uff0c\u5b83\u53ef\u4ee5\u5c06\u5b57\u7b26\u4e32\u76f4\u63a5\u8f6c\u5316\u4e3a\u6d6e\u70b9\u6570\u3002\u4f8b\u5982\uff0c<code>float(&quot;3.14&quot;)<\/code>\u4f1a\u8fd4\u56de3.14\u3002\u5982\u679c\u5b57\u7b26\u4e32\u4e2d\u5305\u542b\u975e\u6570\u5b57\u5b57\u7b26\u6216\u8005\u683c\u5f0f\u4e0d\u6b63\u786e\uff0c\u5219\u4f1a\u629b\u51fa<code>ValueError<\/code>\u5f02\u5e38\uff0c\u56e0\u6b64\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u5fc5\u987b\u8fdb\u884c\u5f02\u5e38\u5904\u7406\u3002\u5bf9\u4e8e\u9700\u8981\u5904\u7406\u5305\u542b\u975e\u6570\u5b57\u5b57\u7b26\u7684\u5b57\u7b26\u4e32\uff0c\u53ef\u4ee5\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u6216\u5b57\u7b26\u4e32\u64cd\u4f5c\u65b9\u6cd5\u6765\u63d0\u53d6\u6570\u5b57\u90e8\u5206\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528float()\u51fd\u6570<\/h3>\n<\/p>\n<p><p><code>float()<\/code>\u51fd\u6570\u662fPython\u5185\u7f6e\u7684\u4e00\u4e2a\u51fd\u6570\uff0c\u5b83\u4e13\u95e8\u7528\u4e8e\u5c06\u5b57\u7b26\u4e32\u7c7b\u578b\u7684\u6570\u636e\u8f6c\u5316\u4e3a\u6d6e\u70b9\u6570\u3002\u5176\u57fa\u672c\u7528\u6cd5\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">string_value = &quot;123.456&quot;<\/p>\n<p>float_value = float(string_value)<\/p>\n<p>print(float_value)  # \u8f93\u51fa\uff1a123.456<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u975e\u5e38\u76f4\u63a5\u548c\u65b9\u4fbf\uff0c\u9002\u7528\u4e8e\u5b57\u7b26\u4e32\u683c\u5f0f\u6b63\u786e\u4e14\u4e0d\u5305\u542b\u975e\u6570\u5b57\u5b57\u7b26\u7684\u60c5\u51b5\u3002\u5982\u679c\u5b57\u7b26\u4e32\u5185\u5bb9\u4e0d\u7b26\u5408\u6d6e\u70b9\u6570\u683c\u5f0f\uff0c\u4f8b\u5982\u5305\u542b\u5b57\u6bcd\u6216\u7279\u6b8a\u5b57\u7b26\uff0c<code>float()<\/code>\u51fd\u6570\u4f1a\u629b\u51fa<code>ValueError<\/code>\u5f02\u5e38\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u5904\u7406\u5f02\u5e38\u60c5\u51b5<\/h3>\n<\/p>\n<p><p>\u4e3a\u4e86\u907f\u514d\u7a0b\u5e8f\u56e0\u5f02\u5e38\u800c\u4e2d\u65ad\uff0c\u53ef\u4ee5\u4f7f\u7528<code>try...except<\/code>\u7ed3\u6784\u6765\u5904\u7406\u53ef\u80fd\u51fa\u73b0\u7684<code>ValueError<\/code>\u5f02\u5e38\u3002\u8fd9\u6837\u53ef\u4ee5\u786e\u4fdd\u7a0b\u5e8f\u5728\u9047\u5230\u5f02\u5e38\u65f6\u4f9d\u7136\u80fd\u591f\u6b63\u5e38\u8fd0\u884c\uff0c\u5e76\u4e14\u53ef\u4ee5\u7ed9\u51fa\u9002\u5f53\u7684\u5904\u7406\u65b9\u5f0f\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">string_value = &quot;123.45abc&quot;<\/p>\n<p>try:<\/p>\n<p>    float_value = float(string_value)<\/p>\n<p>    print(float_value)<\/p>\n<p>except ValueError:<\/p>\n<p>    print(&quot;\u65e0\u6cd5\u5c06\u5b57\u7b26\u4e32\u8f6c\u5316\u4e3a\u6d6e\u70b9\u6570&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u5982\u679c\u5b57\u7b26\u4e32\u4e2d\u5305\u542b\u65e0\u6548\u5b57\u7b26\uff0c\u7a0b\u5e8f\u4e0d\u4f1a\u5d29\u6e83\uff0c\u800c\u662f\u4f1a\u8f93\u51fa&quot;\u65e0\u6cd5\u5c06\u5b57\u7b26\u4e32\u8f6c\u5316\u4e3a\u6d6e\u70b9\u6570&quot;\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u53bb\u9664\u5b57\u7b26\u4e32\u4e2d\u7684\u975e\u6570\u5b57\u5b57\u7b26<\/h3>\n<\/p>\n<p><p>\u6709\u65f6\u9700\u8981\u5904\u7406\u5305\u542b\u975e\u6570\u5b57\u5b57\u7b26\u7684\u5b57\u7b26\u4e32\uff0c\u4f8b\u5982\u5e26\u6709\u8d27\u5e01\u7b26\u53f7\u6216\u5176\u4ed6\u6807\u8bb0\u7684\u5b57\u7b26\u4e32\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u53ef\u4ee5\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u6216\u8005\u5b57\u7b26\u4e32\u64cd\u4f5c\u65b9\u6cd5\u6765\u63d0\u53d6\u6570\u5b57\u90e8\u5206\uff0c\u7136\u540e\u518d\u8fdb\u884c\u8f6c\u6362\u3002<\/p>\n<\/p>\n<p><h4>\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f<\/h4>\n<\/p>\n<p><p>\u6b63\u5219\u8868\u8fbe\u5f0f\u662f\u4e00\u79cd\u5f3a\u5927\u7684\u5b57\u7b26\u4e32\u5904\u7406\u5de5\u5177\uff0c\u53ef\u4ee5\u7528\u6765\u5339\u914d\u548c\u63d0\u53d6\u5b57\u7b26\u4e32\u4e2d\u7684\u7279\u5b9a\u6a21\u5f0f\u3002\u4ee5\u4e0b\u793a\u4f8b\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u4ece\u5b57\u7b26\u4e32\u4e2d\u63d0\u53d6\u6570\u5b57\u90e8\u5206\u5e76\u8f6c\u5316\u4e3a\u6d6e\u70b9\u6570\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import re<\/p>\n<p>string_value = &quot;$123.45&quot;<\/p>\n<p>match = re.search(r&quot;[-+]?\\d*\\.\\d+|\\d+&quot;, string_value)<\/p>\n<p>if match:<\/p>\n<p>    float_value = float(match.group())<\/p>\n<p>    print(float_value)  # \u8f93\u51fa\uff1a123.45<\/p>\n<p>else:<\/p>\n<p>    print(&quot;\u65e0\u6cd5\u4ece\u5b57\u7b26\u4e32\u4e2d\u63d0\u53d6\u6570\u5b57&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c<code>re.search()<\/code>\u51fd\u6570\u7528\u4e8e\u5339\u914d\u5b57\u7b26\u4e32\u4e2d\u7684\u6d6e\u70b9\u6570\u6a21\u5f0f\uff0c\u5982\u679c\u627e\u5230\u5339\u914d\u9879\uff0c\u5219\u5c06\u5176\u8f6c\u5316\u4e3a\u6d6e\u70b9\u6570\u3002<\/p>\n<\/p>\n<p><h4>\u4f7f\u7528\u5b57\u7b26\u4e32\u64cd\u4f5c\u65b9\u6cd5<\/h4>\n<\/p>\n<p><p>\u5982\u679c\u5b57\u7b26\u4e32\u683c\u5f0f\u56fa\u5b9a\u4e14\u7b80\u5355\uff0c\u53ef\u4ee5\u4f7f\u7528\u5b57\u7b26\u4e32\u64cd\u4f5c\u65b9\u6cd5\u6765\u53bb\u9664\u975e\u6570\u5b57\u5b57\u7b26\u3002\u4ee5\u4e0b\u793a\u4f8b\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528\u5b57\u7b26\u4e32\u66ff\u6362\u548c\u5207\u7247\u65b9\u6cd5\u5904\u7406\u5b57\u7b26\u4e32\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">string_value = &quot;$123.45&quot;<\/p>\n<p>cleaned_string = string_value.replace(&quot;$&quot;, &quot;&quot;)<\/p>\n<p>float_value = float(cleaned_string)<\/p>\n<p>print(float_value)  # \u8f93\u51fa\uff1a123.45<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u5b57\u7b26\u683c\u5f0f\u56fa\u5b9a\u7684\u60c5\u51b5\uff0c\u4f8b\u5982\u53bb\u9664\u56fa\u5b9a\u7684\u524d\u7f00\u6216\u540e\u7f00\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u5904\u7406\u5e26\u6709\u79d1\u5b66\u8ba1\u6570\u6cd5\u7684\u5b57\u7b26\u4e32<\/h3>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u573a\u666f\u4e2d\uff0c\u5b57\u7b26\u4e32\u53ef\u80fd\u4f1a\u4ee5\u79d1\u5b66\u8ba1\u6570\u6cd5\u8868\u793a\u6d6e\u70b9\u6570\uff0c\u4f8b\u5982&quot;1.23e4&quot;\u8868\u793a12300\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c<code>float()<\/code>\u51fd\u6570\u4f9d\u7136\u53ef\u4ee5\u6b63\u5e38\u5de5\u4f5c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">string_value = &quot;1.23e4&quot;<\/p>\n<p>float_value = float(string_value)<\/p>\n<p>print(float_value)  # \u8f93\u51fa\uff1a12300.0<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u79d1\u5b66\u8ba1\u6570\u6cd5\u5b57\u7b26\u4e32\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528<code>float()<\/code>\u51fd\u6570\u8fdb\u884c\u8f6c\u6362\uff0c\u4e0d\u9700\u8981\u989d\u5916\u5904\u7406\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u6279\u91cf\u5904\u7406\u5b57\u7b26\u4e32\u5217\u8868<\/h3>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u7ecf\u5e38\u9700\u8981\u5904\u7406\u5305\u542b\u591a\u4e2a\u5b57\u7b26\u4e32\u7684\u5217\u8868\uff0c\u5c06\u5b83\u4eec\u8f6c\u5316\u4e3a\u6d6e\u70b9\u6570\u5217\u8868\u3002\u53ef\u4ee5\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u6216\u8005<code>map()<\/code>\u51fd\u6570\u6765\u5b9e\u73b0\u6279\u91cf\u8f6c\u6362\uff1a<\/p>\n<\/p>\n<p><h4>\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">string_list = [&quot;123.45&quot;, &quot;67.89&quot;, &quot;0.12&quot;]<\/p>\n<p>float_list = [float(value) for value in string_list]<\/p>\n<p>print(float_list)  # \u8f93\u51fa\uff1a[123.45, 67.89, 0.12]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u4f7f\u7528map()\u51fd\u6570<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">string_list = [&quot;123.45&quot;, &quot;67.89&quot;, &quot;0.12&quot;]<\/p>\n<p>float_list = list(map(float, string_list))<\/p>\n<p>print(float_list)  # \u8f93\u51fa\uff1a[123.45, 67.89, 0.12]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4e24\u79cd\u65b9\u6cd5\u90fd\u53ef\u4ee5\u9ad8\u6548\u5730\u5c06\u5b57\u7b26\u4e32\u5217\u8868\u8f6c\u5316\u4e3a\u6d6e\u70b9\u6570\u5217\u8868\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u5904\u7406\u5305\u542b\u9017\u53f7\u7684\u6570\u5b57\u5b57\u7b26\u4e32<\/h3>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u5730\u533a\uff0c\u6570\u5b57\u4ee5\u9017\u53f7\u4f5c\u4e3a\u5c0f\u6570\u70b9\u5206\u9694\u7b26\u3002\u4f8b\u5982\uff0c&quot;123,45&quot;\u8868\u793a123.45\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u9700\u8981\u5148\u5c06\u9017\u53f7\u66ff\u6362\u4e3a\u70b9\uff0c\u7136\u540e\u518d\u8fdb\u884c\u8f6c\u6362\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">string_value = &quot;123,45&quot;<\/p>\n<p>cleaned_string = string_value.replace(&quot;,&quot;, &quot;.&quot;)<\/p>\n<p>float_value = float(cleaned_string)<\/p>\n<p>print(float_value)  # \u8f93\u51fa\uff1a123.45<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u5904\u7406\u56fd\u9645\u5316\u683c\u5f0f\u7684\u6570\u5b57\u5b57\u7b26\u4e32\u3002<\/p>\n<\/p>\n<p><h3>\u4e03\u3001\u5904\u7406\u5305\u542b\u7a7a\u683c\u7684\u6570\u5b57\u5b57\u7b26\u4e32<\/h3>\n<\/p>\n<p><p>\u6709\u65f6\u5b57\u7b26\u4e32\u4e2d\u53ef\u80fd\u5305\u542b\u7a7a\u683c\uff0c\u8fd9\u4e9b\u7a7a\u683c\u9700\u8981\u5728\u8f6c\u6362\u524d\u53bb\u9664\u3002\u53ef\u4ee5\u4f7f\u7528<code>strip()<\/code>\u65b9\u6cd5\u53bb\u9664\u5b57\u7b26\u4e32\u4e24\u7aef\u7684\u7a7a\u683c\uff0c\u6216\u8005\u4f7f\u7528<code>replace()<\/code>\u65b9\u6cd5\u53bb\u9664\u5b57\u7b26\u4e32\u4e2d\u7684\u6240\u6709\u7a7a\u683c\uff1a<\/p>\n<\/p>\n<p><h4>\u53bb\u9664\u4e24\u7aef\u7a7a\u683c<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">string_value = &quot;  123.45  &quot;<\/p>\n<p>cleaned_string = string_value.strip()<\/p>\n<p>float_value = float(cleaned_string)<\/p>\n<p>print(float_value)  # \u8f93\u51fa\uff1a123.45<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u53bb\u9664\u6240\u6709\u7a7a\u683c<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">string_value = &quot;12 3.45&quot;<\/p>\n<p>cleaned_string = string_value.replace(&quot; &quot;, &quot;&quot;)<\/p>\n<p>float_value = float(cleaned_string)<\/p>\n<p>print(float_value)  # \u8f93\u51fa\uff1a123.45<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u5904\u7406\u5305\u542b\u7a7a\u683c\u7684\u6570\u5b57\u5b57\u7b26\u4e32\u3002<\/p>\n<\/p>\n<p><h3>\u516b\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5c06\u5b57\u7b26\u4e32\u8f6c\u5316\u4e3a\u6d6e\u70b9\u6570\u662fPython\u4e2d\u5e38\u89c1\u7684\u64cd\u4f5c\uff0c<strong>\u4f7f\u7528<code>float()<\/code>\u51fd\u6570\u662f\u6700\u7b80\u5355\u548c\u76f4\u63a5\u7684\u65b9\u6cd5<\/strong>\u3002\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c<strong>\u5904\u7406\u5f02\u5e38\u60c5\u51b5\u3001\u53bb\u9664\u975e\u6570\u5b57\u5b57\u7b26\u548c\u5904\u7406\u7279\u6b8a\u683c\u5f0f\u5b57\u7b26\u4e32\u662f\u5e38\u89c1\u7684\u9700\u6c42<\/strong>\u3002\u901a\u8fc7\u7ed3\u5408\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u3001\u5b57\u7b26\u4e32\u64cd\u4f5c\u65b9\u6cd5\u548c\u5f02\u5e38\u5904\u7406\uff0c\u53ef\u4ee5\u9ad8\u6548\u5730\u5904\u7406\u5404\u79cd\u590d\u6742\u60c5\u51b5\u3002\u5e0c\u671b\u672c\u6587\u4ecb\u7ecd\u7684\u65b9\u6cd5\u548c\u6280\u5de7\u80fd\u5e2e\u52a9\u60a8\u66f4\u597d\u5730\u5904\u7406\u5b57\u7b26\u4e32\u5230\u6d6e\u70b9\u6570\u7684\u8f6c\u6362\u95ee\u9898\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u6d6e\u70b9\u6570\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u5185\u7f6e\u7684<code>float()<\/code>\u51fd\u6570\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u6d6e\u70b9\u6570\u3002\u4f8b\u5982\uff0c\u6267\u884c<code>float(&quot;3.14&quot;)<\/code>\u5c06\u8fd4\u56de3.14\u3002\u5982\u679c\u5b57\u7b26\u4e32\u4e2d\u5305\u542b\u6709\u6548\u7684\u6570\u5b57\u683c\u5f0f\uff0c<code>float()<\/code>\u51fd\u6570\u5c06\u80fd\u591f\u6210\u529f\u8f6c\u6362\u3002<\/p>\n<p><strong>\u5982\u679c\u5b57\u7b26\u4e32\u5305\u542b\u975e\u6570\u5b57\u5b57\u7b26\uff0c\u8be5\u5982\u4f55\u5904\u7406\uff1f<\/strong><br \/>\u5f53\u5b57\u7b26\u4e32\u4e2d\u5305\u542b\u975e\u6570\u5b57\u5b57\u7b26\u65f6\uff0c\u5c1d\u8bd5\u5c06\u5176\u8f6c\u6362\u4e3a\u6d6e\u70b9\u6570\u4f1a\u5f15\u53d1<code>ValueError<\/code>\u5f02\u5e38\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u53ef\u4ee5\u4f7f\u7528<code>try...except<\/code>\u8bed\u53e5\u6765\u6355\u83b7\u5f02\u5e38\u5e76\u8fdb\u884c\u76f8\u5e94\u7684\u5904\u7406\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u63d0\u793a\u7528\u6237\u8f93\u5165\u6709\u6548\u7684\u6570\u5b57\u3002<\/p>\n<p><strong>\u5982\u4f55\u5904\u7406\u5305\u542b\u7a7a\u683c\u7684\u5b57\u7b26\u4e32\uff1f<\/strong><br \/>\u5982\u679c\u5b57\u7b26\u4e32\u5305\u542b\u7a7a\u683c\uff0c\u4f7f\u7528<code>float()<\/code>\u51fd\u6570\u65f6\uff0c\u5b83\u4f1a\u81ea\u52a8\u5ffd\u7565\u524d\u540e\u7684\u7a7a\u683c\u3002\u4f8b\u5982\uff0c<code>float(&quot;  3.14  &quot;)<\/code>\u5c06\u8fd4\u56de3.14\u3002\u5982\u679c\u9700\u8981\u5904\u7406\u5b57\u7b26\u4e32\u4e2d\u7684\u4e2d\u95f4\u7a7a\u683c\uff0c\u53ef\u4ee5\u5148\u4f7f\u7528<code>replace()<\/code>\u65b9\u6cd5\u79fb\u9664\u6216\u66ff\u6362\u7a7a\u683c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u5c06\u5b57\u7b26\u4e32\u8f6c\u5316\u4e3afloat\u7684\u65b9\u6cd5\u6709\uff1a\u4f7f\u7528float()\u51fd\u6570\u3001\u5904\u7406\u5f02\u5e38\u60c5\u51b5\u3001\u53bb\u9664\u5b57\u7b26\u4e32\u4e2d\u7684\u975e\u6570\u5b57\u5b57\u7b26\u3002 [&hellip;]","protected":false},"author":3,"featured_media":1073528,"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\/1073523"}],"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=1073523"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1073523\/revisions"}],"predecessor-version":[{"id":1073530,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1073523\/revisions\/1073530"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1073528"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1073523"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1073523"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1073523"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}