{"id":1112586,"date":"2025-01-08T17:39:53","date_gmt":"2025-01-08T09:39:53","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1112586.html"},"modified":"2025-01-08T17:39:57","modified_gmt":"2025-01-08T09:39:57","slug":"python%e5%a6%82%e4%bd%95%e5%b0%86%e5%88%97%e8%a1%a8%e7%9a%84%e6%95%b0%e4%bf%9d%e7%95%99%e5%b0%8f%e6%95%b0","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1112586.html","title":{"rendered":"python\u5982\u4f55\u5c06\u5217\u8868\u7684\u6570\u4fdd\u7559\u5c0f\u6570"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25074545\/cbcb2306-b69d-42d1-b35a-626560932bca.webp\" alt=\"python\u5982\u4f55\u5c06\u5217\u8868\u7684\u6570\u4fdd\u7559\u5c0f\u6570\" \/><\/p>\n<p><p> <strong>Python\u5982\u4f55\u5c06\u5217\u8868\u7684\u6570\u4fdd\u7559\u5c0f\u6570\uff0c\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u6cd5\u5b9e\u73b0\uff0c\u4f8b\u5982\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u3001map\u51fd\u6570\u3001\u6216\u8005\u662flambda\u51fd\u6570\u3002<\/strong>\u4e0b\u9762\u6211\u4eec\u5c06\u901a\u8fc7\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u4e9b\u65b9\u6cd5\u6765\u5e2e\u52a9\u60a8\u66f4\u597d\u5730\u7406\u89e3\u548c\u8fd0\u7528\u8fd9\u4e9b\u6280\u672f\u3002<\/p>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u5904\u7406\u4fdd\u7559\u5c0f\u6570\u7684\u64cd\u4f5c\u901a\u5e38\u4f1a\u7528\u5230<code>round()<\/code>\u51fd\u6570\u3002<code>round()<\/code>\u51fd\u6570\u53ef\u4ee5\u5c06\u4e00\u4e2a\u6570\u5b57\u56db\u820d\u4e94\u5165\u5230\u6307\u5b9a\u7684\u5c0f\u6570\u4f4d\u6570\u3002\u4f8b\u5982\uff0c\u5982\u679c\u6211\u4eec\u60f3\u8981\u5c06\u4e00\u4e2a\u6570\u4fdd\u7559\u4e24\u4f4d\u5c0f\u6570\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528<code>round(number, 2)<\/code>\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f<\/h3>\n<\/p>\n<p><p>\u5217\u8868\u63a8\u5bfc\u5f0f\u662f\u4e00\u79cd\u7b80\u6d01\u4e14\u9ad8\u6548\u7684\u65b9\u5f0f\u6765\u521b\u5efa\u5217\u8868\u3002\u5b83\u5141\u8bb8\u6211\u4eec\u5728\u4e00\u884c\u4ee3\u7801\u4e2d\u5b8c\u6210\u5217\u8868\u7684\u751f\u6210\u548c\u8f6c\u6362\u3002\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\uff0c\u6211\u4eec\u53ef\u4ee5\u5f88\u65b9\u4fbf\u5730\u5c06\u5217\u8868\u4e2d\u7684\u6bcf\u4e2a\u6570\u4fdd\u7559\u5c0f\u6570\u4f4d\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">original_list = [3.14159, 2.71828, 1.61803, 0.57721]<\/p>\n<p>rounded_list = [round(num, 2) for num in original_list]<\/p>\n<p>print(rounded_list)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u5c06<code>original_list<\/code>\u4e2d\u7684\u6bcf\u4e2a\u6570\u90fd\u4fdd\u7559\u4e24\u4f4d\u5c0f\u6570\uff0c\u5e76\u751f\u6210\u4e86\u4e00\u4e2a\u65b0\u7684\u5217\u8868<code>rounded_list<\/code>\u3002\u5217\u8868\u63a8\u5bfc\u5f0f\u662f\u975e\u5e38\u76f4\u89c2\u7684\uff0c\u4ee3\u7801\u4e5f\u76f8\u5bf9\u7b80\u6d01\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528 map() \u51fd\u6570<\/h3>\n<\/p>\n<p><p><code>map()<\/code>\u51fd\u6570\u7528\u4e8e\u5c06\u4e00\u4e2a\u51fd\u6570\u5e94\u7528\u5230\u4e00\u4e2a\u6216\u591a\u4e2a\u5e8f\u5217\u7684\u6bcf\u4e2a\u5143\u7d20\u4e0a\uff0c\u5e76\u8fd4\u56de\u4e00\u4e2a\u8fed\u4ee3\u5668\u3002\u6211\u4eec\u53ef\u4ee5\u7ed3\u5408<code>round()<\/code>\u51fd\u6570\u548c<code>map()<\/code>\u51fd\u6570\u6765\u5b9e\u73b0\u5217\u8868\u4e2d\u6bcf\u4e2a\u6570\u4fdd\u7559\u5c0f\u6570\u4f4d\u7684\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">original_list = [3.14159, 2.71828, 1.61803, 0.57721]<\/p>\n<p>rounded_list = list(map(lambda x: round(x, 2), original_list))<\/p>\n<p>print(rounded_list)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u4e86<code>lambda<\/code>\u51fd\u6570\u6765\u5b9a\u4e49\u4e00\u4e2a\u533f\u540d\u51fd\u6570\uff0c<code>lambda x: round(x, 2)<\/code>\uff0c\u5b83\u5c06\u6bcf\u4e2a\u6570\u4fdd\u7559\u4e24\u4f4d\u5c0f\u6570\u3002\u7136\u540e\uff0c\u6211\u4eec\u4f7f\u7528<code>map()<\/code>\u51fd\u6570\u5c06\u8fd9\u4e2a\u533f\u540d\u51fd\u6570\u5e94\u7528\u5230<code>original_list<\/code>\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\uff0c\u6700\u7ec8\u751f\u6210\u4e86\u4e00\u4e2a\u65b0\u7684\u5217\u8868<code>rounded_list<\/code>\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528\u5faa\u73af<\/h3>\n<\/p>\n<p><p>\u867d\u7136\u5217\u8868\u63a8\u5bfc\u5f0f\u548c<code>map()<\/code>\u51fd\u6570\u5f88\u7b80\u6d01\uff0c\u4f46\u6709\u65f6\u5019\u6211\u4eec\u53ef\u80fd\u9700\u8981\u66f4\u52a0\u7075\u6d3b\u7684\u64cd\u4f5c\uff0c\u8fd9\u65f6\u53ef\u4ee5\u4f7f\u7528\u5faa\u73af\u6765\u5b9e\u73b0\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">original_list = [3.14159, 2.71828, 1.61803, 0.57721]<\/p>\n<p>rounded_list = []<\/p>\n<p>for num in original_list:<\/p>\n<p>    rounded_list.append(round(num, 2))<\/p>\n<p>print(rounded_list)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u4e86\u4e00\u4e2a<code>for<\/code>\u5faa\u73af\u6765\u904d\u5386<code>original_list<\/code>\u4e2d\u7684\u6bcf\u4e2a\u6570\uff0c\u5e76\u5c06\u6bcf\u4e2a\u6570\u4fdd\u7559\u4e24\u4f4d\u5c0f\u6570\u540e\u6dfb\u52a0\u5230<code>rounded_list<\/code>\u4e2d\u3002\u8fd9\u79cd\u65b9\u6cd5\u867d\u7136\u4ee3\u7801\u7a0d\u957f\uff0c\u4f46\u66f4\u52a0\u6e05\u6670\u6613\u61c2\uff0c\u9002\u5408\u590d\u6742\u7684\u5904\u7406\u903b\u8f91\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u4f7f\u7528 NumPy \u5e93<\/h3>\n<\/p>\n<p><p>\u5982\u679c\u60a8\u5728\u5904\u7406\u5927\u91cf\u6570\u636e\u6216\u8fdb\u884c\u79d1\u5b66\u8ba1\u7b97\uff0c\u63a8\u8350\u4f7f\u7528NumPy\u5e93\u3002NumPy\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u79d1\u5b66\u8ba1\u7b97\u5e93\uff0c\u63d0\u4f9b\u4e86\u5f88\u591a\u9ad8\u6548\u7684\u6570\u7ec4\u64cd\u4f5c\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>original_list = [3.14159, 2.71828, 1.61803, 0.57721]<\/p>\n<p>np_array = np.array(original_list)<\/p>\n<p>rounded_array = np.round(np_array, 2)<\/p>\n<p>rounded_list = rounded_array.tolist()<\/p>\n<p>print(rounded_list)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u5c06\u5217\u8868\u8f6c\u6362\u4e3aNumPy\u6570\u7ec4\uff0c\u7136\u540e\u4f7f\u7528<code>np.round()<\/code>\u51fd\u6570\u5c06\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u6570\u4fdd\u7559\u4e24\u4f4d\u5c0f\u6570\uff0c\u6700\u540e\u5c06NumPy\u6570\u7ec4\u8f6c\u6362\u56de\u5217\u8868\u3002NumPy\u5e93\u5728\u5904\u7406\u5927\u89c4\u6a21\u6570\u636e\u65f6\u6548\u7387\u66f4\u9ad8\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u4f7f\u7528 pandas \u5e93<\/h3>\n<\/p>\n<p><p>\u5982\u679c\u60a8\u5904\u7406\u7684\u6570\u636e\u662f\u8868\u683c\u5f62\u5f0f\u7684\uff0c\u63a8\u8350\u4f7f\u7528pandas\u5e93\u3002Pandas\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u6570\u636e\u5206\u6790\u5de5\u5177\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u5904\u7406\u548c\u64cd\u4f5c\u8868\u683c\u6570\u636e\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>data = {&#39;numbers&#39;: [3.14159, 2.71828, 1.61803, 0.57721]}<\/p>\n<p>df = pd.DataFrame(data)<\/p>\n<p>df[&#39;rounded_numbers&#39;] = df[&#39;numbers&#39;].round(2)<\/p>\n<p>print(df)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u5305\u542b\u6570\u5b57\u7684DataFrame\uff0c\u5e76\u4f7f\u7528<code>round()<\/code>\u65b9\u6cd5\u5c06\u6bcf\u4e2a\u6570\u4fdd\u7559\u4e24\u4f4d\u5c0f\u6570\u3002Pandas\u5e93\u5728\u5904\u7406\u548c\u5206\u6790\u8868\u683c\u6570\u636e\u65f6\u975e\u5e38\u65b9\u4fbf\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u4f7f\u7528\u81ea\u5b9a\u4e49\u51fd\u6570<\/h3>\n<\/p>\n<p><p>\u6709\u65f6\u5019\u60a8\u53ef\u80fd\u9700\u8981\u5bf9\u4fdd\u7559\u5c0f\u6570\u7684\u64cd\u4f5c\u8fdb\u884c\u5c01\u88c5\uff0c\u4ee5\u4fbf\u5728\u591a\u4e2a\u5730\u65b9\u91cd\u590d\u4f7f\u7528\u3002\u8fd9\u65f6\u53ef\u4ee5\u5b9a\u4e49\u4e00\u4e2a\u81ea\u5b9a\u4e49\u51fd\u6570\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def round_list(numbers, decimal_places):<\/p>\n<p>    return [round(num, decimal_places) for num in numbers]<\/p>\n<p>original_list = [3.14159, 2.71828, 1.61803, 0.57721]<\/p>\n<p>rounded_list = round_list(original_list, 2)<\/p>\n<p>print(rounded_list)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a<code>round_list()<\/code>\u51fd\u6570\uff0c\u8be5\u51fd\u6570\u63a5\u53d7\u4e00\u4e2a\u5217\u8868\u548c\u9700\u8981\u4fdd\u7559\u7684\u5c0f\u6570\u4f4d\u6570\u4f5c\u4e3a\u53c2\u6570\uff0c\u5e76\u8fd4\u56de\u4e00\u4e2a\u4fdd\u7559\u5c0f\u6570\u540e\u7684\u65b0\u5217\u8868\u3002\u8fd9\u6837\u53ef\u4ee5\u4f7f\u4ee3\u7801\u66f4\u52a0\u6a21\u5757\u5316\u548c\u6613\u4e8e\u7ef4\u62a4\u3002<\/p>\n<\/p>\n<p><h3>\u4e03\u3001\u5904\u7406\u4e0d\u540c\u7c7b\u578b\u7684\u6570\u636e<\/h3>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u6211\u4eec\u53ef\u80fd\u4f1a\u9047\u5230\u5305\u542b\u4e0d\u540c\u7c7b\u578b\u6570\u636e\u7684\u5217\u8868\uff0c\u4f8b\u5982\u6574\u6570\u3001\u6d6e\u70b9\u6570\u548c\u5b57\u7b26\u4e32\u3002\u6211\u4eec\u9700\u8981\u786e\u4fdd\u53ea\u5bf9\u6d6e\u70b9\u6570\u8fdb\u884c\u4fdd\u7559\u5c0f\u6570\u4f4d\u7684\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">original_list = [3.14159, 2.71828, 1, &#39;hello&#39;, 0.57721]<\/p>\n<p>rounded_list = [round(num, 2) if isinstance(num, float) else num for num in original_list]<\/p>\n<p>print(rounded_list)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>isinstance()<\/code>\u51fd\u6570\u6765\u68c0\u67e5\u5217\u8868\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u662f\u5426\u662f\u6d6e\u70b9\u6570\uff0c\u5982\u679c\u662f\u5219\u4fdd\u7559\u4e24\u4f4d\u5c0f\u6570\uff0c\u5426\u5219\u4fdd\u6301\u539f\u6837\u3002\u8fd9\u79cd\u65b9\u6cd5\u53ef\u4ee5\u6709\u6548\u5730\u5904\u7406\u6df7\u5408\u7c7b\u578b\u7684\u6570\u636e\u3002<\/p>\n<\/p>\n<p><h3>\u516b\u3001\u5904\u7406\u591a\u7ef4\u5217\u8868<\/h3>\n<\/p>\n<p><p>\u6709\u65f6\u5019\u6211\u4eec\u9700\u8981\u5904\u7406\u5305\u542b\u591a\u4e2a\u5b50\u5217\u8868\u7684\u591a\u7ef4\u5217\u8868\uff0c\u8fd9\u65f6\u53ef\u4ee5\u4f7f\u7528\u9012\u5f52\u51fd\u6570\u6765\u5b9e\u73b0\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def round_nested_list(nested_list, decimal_places):<\/p>\n<p>    rounded_list = []<\/p>\n<p>    for item in nested_list:<\/p>\n<p>        if isinstance(item, list):<\/p>\n<p>            rounded_list.append(round_nested_list(item, decimal_places))<\/p>\n<p>        elif isinstance(item, float):<\/p>\n<p>            rounded_list.append(round(item, decimal_places))<\/p>\n<p>        else:<\/p>\n<p>            rounded_list.append(item)<\/p>\n<p>    return rounded_list<\/p>\n<p>original_list = [[3.14159, 2.71828], [1.61803, 0.57721, &#39;hello&#39;]]<\/p>\n<p>rounded_list = round_nested_list(original_list, 2)<\/p>\n<p>print(rounded_list)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a\u9012\u5f52\u51fd\u6570<code>round_nested_list()<\/code>\uff0c\u8be5\u51fd\u6570\u53ef\u4ee5\u5904\u7406\u591a\u7ef4\u5217\u8868\u4e2d\u7684\u6bcf\u4e2a\u6d6e\u70b9\u6570\uff0c\u5e76\u4fdd\u7559\u6307\u5b9a\u7684\u5c0f\u6570\u4f4d\u3002\u8fd9\u79cd\u65b9\u6cd5\u53ef\u4ee5\u5904\u7406\u4efb\u610f\u6df1\u5ea6\u7684\u5d4c\u5957\u5217\u8868\u3002<\/p>\n<\/p>\n<p><h3>\u4e5d\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u8ba8\u8bba\u4e86\u5728Python\u4e2d\u5c06\u5217\u8868\u7684\u6570\u4fdd\u7559\u5c0f\u6570\u7684\u591a\u79cd\u65b9\u6cd5\uff0c\u5305\u62ec\u5217\u8868\u63a8\u5bfc\u5f0f\u3001<code>map()<\/code>\u51fd\u6570\u3001\u5faa\u73af\u3001NumPy\u5e93\u3001pandas\u5e93\u3001\u81ea\u5b9a\u4e49\u51fd\u6570\u3001\u5904\u7406\u4e0d\u540c\u7c7b\u578b\u7684\u6570\u636e\u4ee5\u53ca\u5904\u7406\u591a\u7ef4\u5217\u8868\u3002\u6bcf\u79cd\u65b9\u6cd5\u90fd\u6709\u5176\u4f18\u7f3a\u70b9\uff0c\u9009\u62e9\u54ea\u79cd\u65b9\u6cd5\u53d6\u51b3\u4e8e\u5177\u4f53\u7684\u5e94\u7528\u573a\u666f\u548c\u9700\u6c42\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u672c\u6587\u7684\u4ecb\u7ecd\uff0c\u60a8\u5e94\u8be5\u80fd\u591f\u6839\u636e\u81ea\u5df1\u7684\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u6765\u5904\u7406\u5217\u8868\u4e2d\u7684\u6570\u4fdd\u7559\u5c0f\u6570\u4f4d\u7684\u64cd\u4f5c\u3002\u5e0c\u671b\u8fd9\u4e9b\u5185\u5bb9\u5bf9\u60a8\u6709\u6240\u5e2e\u52a9\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u5c06\u5217\u8868\u4e2d\u7684\u6570\u5b57\u683c\u5f0f\u5316\u4e3a\u7279\u5b9a\u7684\u5c0f\u6570\u4f4d\u6570\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u548c\u5185\u7f6e\u7684<code>round()<\/code>\u51fd\u6570\u6765\u683c\u5f0f\u5316\u5217\u8868\u4e2d\u7684\u6570\u5b57\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u60f3\u5c06\u6bcf\u4e2a\u6570\u5b57\u4fdd\u7559\u4e24\u4f4d\u5c0f\u6570\uff0c\u53ef\u4ee5\u8fd9\u6837\u505a\uff1a<code>formatted_list = [round(num, 2) for num in original_list]<\/code>\u3002\u8fd9\u4e2a\u65b9\u6cd5\u7b80\u5355\u4e14\u9ad8\u6548\uff0c\u53ef\u4ee5\u6ee1\u8db3\u5927\u591a\u6570\u57fa\u672c\u9700\u6c42\u3002<\/p>\n<p><strong>Python\u4e2d\u6709\u54ea\u4e9b\u65b9\u6cd5\u53ef\u4ee5\u5c06\u6d6e\u70b9\u6570\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u5e76\u4fdd\u7559\u5c0f\u6570\u4f4d\uff1f<\/strong><br \/>Python\u63d0\u4f9b\u4e86\u591a\u79cd\u65b9\u5f0f\u5c06\u6d6e\u70b9\u6570\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u5e76\u4fdd\u7559\u7279\u5b9a\u7684\u5c0f\u6570\u4f4d\u3002\u53ef\u4ee5\u4f7f\u7528\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\uff0c\u4f8b\u5982\uff1a<code>formatted_string = &quot;{:.2f}&quot;.format(num)<\/code>\u6216\u4f7f\u7528f\u5b57\u7b26\u4e32\uff1a<code>formatted_string = f&quot;{num:.2f}&quot;<\/code>\u3002\u8fd9\u4e24\u79cd\u65b9\u5f0f\u90fd\u80fd\u7075\u6d3b\u5730\u63a7\u5236\u5c0f\u6570\u4f4d\u6570\uff0c\u975e\u5e38\u9002\u5408\u5728\u8f93\u51fa\u65f6\u4f7f\u7528\u3002<\/p>\n<p><strong>\u5982\u4f55\u5904\u7406\u5305\u542b\u8d1f\u6570\u7684\u5217\u8868\u4ee5\u4fdd\u7559\u5c0f\u6570\uff1f<\/strong><br \/>\u5bf9\u5305\u542b\u8d1f\u6570\u7684\u5217\u8868\u8fdb\u884c\u5c0f\u6570\u4fdd\u7559\u548c\u6b63\u6570\u5904\u7406\u662f\u4e00\u6837\u7684\u3002\u4f7f\u7528<code>round()<\/code>\u51fd\u6570\u6216\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u65f6\uff0c\u8d1f\u6570\u4e5f\u4f1a\u81ea\u52a8\u5f97\u5230\u76f8\u540c\u7684\u5904\u7406\u3002\u4f8b\u5982\uff0c<code>rounded_list = [round(num, 2) for num in original_list]<\/code>\u4f1a\u4fdd\u7559\u8d1f\u6570\u7684\u5c0f\u6570\u4f4d\uff0c\u786e\u4fdd\u6240\u6709\u6570\u5b57\u7684\u4e00\u81f4\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u5982\u4f55\u5c06\u5217\u8868\u7684\u6570\u4fdd\u7559\u5c0f\u6570\uff0c\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u6cd5\u5b9e\u73b0\uff0c\u4f8b\u5982\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u3001map\u51fd\u6570\u3001\u6216\u8005\u662flambda\u51fd [&hellip;]","protected":false},"author":3,"featured_media":1112598,"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\/1112586"}],"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=1112586"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1112586\/revisions"}],"predecessor-version":[{"id":1112601,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1112586\/revisions\/1112601"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1112598"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1112586"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1112586"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1112586"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}