{"id":1152188,"date":"2025-01-13T17:22:44","date_gmt":"2025-01-13T09:22:44","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1152188.html"},"modified":"2025-01-13T17:22:47","modified_gmt":"2025-01-13T09:22:47","slug":"python%e5%a6%82%e4%bd%95%e7%94%b3%e8%af%b7%e5%88%97%e8%a1%a8%e7%a9%ba%e9%97%b4","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1152188.html","title":{"rendered":"Python\u5982\u4f55\u7533\u8bf7\u5217\u8868\u7a7a\u95f4"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25182242\/b80d30e8-3051-41d1-ab44-5c48a8bdeaa1.webp\" alt=\"Python\u5982\u4f55\u7533\u8bf7\u5217\u8868\u7a7a\u95f4\" \/><\/p>\n<p><p> <strong>Python\u7533\u8bf7\u5217\u8868\u7a7a\u95f4\u7684\u65b9\u6cd5\u5305\u62ec\u76f4\u63a5\u521b\u5efa\u5217\u8868\u3001\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u3001\u4f7f\u7528\u4e58\u6cd5\u8fd0\u7b97\u7b26\u521b\u5efa\u56fa\u5b9a\u957f\u5ea6\u7684\u5217\u8868\u3001\u4f7f\u7528\u5185\u7f6e\u51fd\u6570\u7b49\u3002<\/strong> \u5176\u4e2d\uff0c\u76f4\u63a5\u521b\u5efa\u5217\u8868\u548c\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u662f\u6700\u5e38\u7528\u7684\u65b9\u6cd5\u3002\u76f4\u63a5\u521b\u5efa\u5217\u8868\u6700\u4e3a\u7b80\u5355\uff0c\u901a\u8fc7\u4f7f\u7528\u65b9\u62ec\u53f7[]\u5373\u53ef\u521b\u5efa\u4e00\u4e2a\u7a7a\u5217\u8868\u6216\u5305\u542b\u521d\u59cb\u5143\u7d20\u7684\u5217\u8868\u3002\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u53ef\u4ee5\u5feb\u901f\u751f\u6210\u7279\u5b9a\u6a21\u5f0f\u7684\u5217\u8868\uff0c\u9002\u5408\u9700\u8981\u6839\u636e\u7279\u5b9a\u89c4\u5219\u751f\u6210\u5217\u8868\u7684\u573a\u666f\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5176\u4e2d\u4e00\u79cd\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><h3>\u5217\u8868\u63a8\u5bfc\u5f0f<\/h3>\n<\/p>\n<p><p>\u5217\u8868\u63a8\u5bfc\u5f0f\u662f\u4e00\u79cd\u7b80\u6d01\u7684\u521b\u5efa\u5217\u8868\u7684\u65b9\u6cd5\u3002\u5b83\u7684\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">[expression for item in iterable]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5176\u4e2d\uff0cexpression\u662f\u4e00\u4e2a\u8868\u8fbe\u5f0f\uff0c\u7528\u4e8e\u8ba1\u7b97\u65b0\u5217\u8868\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\uff0citem\u662f\u4eceiterable\u4e2d\u4f9d\u6b21\u53d6\u51fa\u7684\u5143\u7d20\u3002\u5217\u8868\u63a8\u5bfc\u5f0f\u4e0d\u4ec5\u8bed\u6cd5\u7b80\u6d01\uff0c\u800c\u4e14\u901a\u5e38\u6267\u884c\u6548\u7387\u66f4\u9ad8\u3002<\/p>\n<\/p>\n<p><p>\u4e3e\u4f8b\u6765\u8bf4\uff0c\u521b\u5efa\u4e00\u4e2a\u5305\u542b\u524d10\u4e2a\u6574\u6570\u7684\u5217\u8868\uff0c\u53ef\u4ee5\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">numbers = [i for i in range(10)]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6837\u5c31\u751f\u6210\u4e86\u4e00\u4e2a\u5305\u542b\u4ece0\u52309\u7684\u6574\u6570\u5217\u8868\u3002<\/p>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecdPython\u7533\u8bf7\u5217\u8868\u7a7a\u95f4\u7684\u5404\u79cd\u65b9\u6cd5\uff0c\u5e76\u5206\u6790\u5176\u4f18\u7f3a\u70b9\u548c\u9002\u7528\u573a\u666f\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u76f4\u63a5\u521b\u5efa\u5217\u8868<\/h3>\n<\/p>\n<p><h4>1\u3001\u521b\u5efa\u7a7a\u5217\u8868<\/h4>\n<\/p>\n<p><p>\u76f4\u63a5\u521b\u5efa\u4e00\u4e2a\u7a7a\u5217\u8868\u662f\u6700\u57fa\u672c\u7684\u65b9\u5f0f\u3002\u8fd9\u79cd\u65b9\u6cd5\u975e\u5e38\u7b80\u5355\uff0c\u53ea\u9700\u8981\u4f7f\u7528\u4e00\u5bf9\u65b9\u62ec\u53f7\u5373\u53ef\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">empty_list = []<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u9700\u8981\u4e00\u4e2a\u7a7a\u5217\u8868\uff0c\u540e\u7eed\u518d\u5411\u5176\u4e2d\u6dfb\u52a0\u5143\u7d20\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u521b\u5efa\u5305\u542b\u521d\u59cb\u5143\u7d20\u7684\u5217\u8868<\/h4>\n<\/p>\n<p><p>\u4e5f\u53ef\u4ee5\u76f4\u63a5\u521b\u5efa\u4e00\u4e2a\u5305\u542b\u521d\u59cb\u5143\u7d20\u7684\u5217\u8868\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">numbers = [1, 2, 3, 4, 5]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u4e00\u5f00\u59cb\u5c31\u77e5\u9053\u5217\u8868\u521d\u59cb\u5143\u7d20\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f<\/h3>\n<\/p>\n<p><h4>1\u3001\u751f\u6210\u6570\u503c\u5e8f\u5217<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u53ef\u4ee5\u5feb\u901f\u751f\u6210\u7279\u5b9a\u6a21\u5f0f\u7684\u6570\u503c\u5e8f\u5217\u3002\u4f8b\u5982\uff0c\u751f\u6210\u4e00\u4e2a\u5305\u542b\u524d10\u4e2a\u6574\u6570\u7684\u5217\u8868\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">numbers = [i for i in range(10)]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u6839\u636e\u7279\u5b9a\u89c4\u5219\u751f\u6210\u6570\u503c\u5e8f\u5217\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u751f\u6210\u5e73\u65b9\u6570\u5e8f\u5217<\/h4>\n<\/p>\n<p><p>\u5217\u8868\u63a8\u5bfc\u5f0f\u8fd8\u53ef\u4ee5\u7528\u4e8e\u751f\u6210\u5e73\u65b9\u6570\u5e8f\u5217\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">squares = [i  2 for i in range(10)]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u9700\u8981\u751f\u6210\u5e73\u65b9\u6570\u6216\u5176\u4ed6\u590d\u6742\u89c4\u5219\u7684\u6570\u5217\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<p><h4>3\u3001\u8fc7\u6ee4\u6761\u4ef6<\/h4>\n<\/p>\n<p><p>\u5217\u8868\u63a8\u5bfc\u5f0f\u8fd8\u53ef\u4ee5\u5305\u542b\u8fc7\u6ee4\u6761\u4ef6\u3002\u4f8b\u5982\uff0c\u751f\u6210\u4e00\u4e2a\u5305\u542b\u524d10\u4e2a\u5076\u6570\u7684\u5217\u8868\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">even_numbers = [i for i in range(20) if i % 2 == 0]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u9700\u8981\u6839\u636e\u7279\u5b9a\u6761\u4ef6\u8fc7\u6ee4\u5143\u7d20\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528\u4e58\u6cd5\u8fd0\u7b97\u7b26\u521b\u5efa\u56fa\u5b9a\u957f\u5ea6\u7684\u5217\u8868<\/h3>\n<\/p>\n<p><h4>1\u3001\u521b\u5efa\u56fa\u5b9a\u957f\u5ea6\u7684\u5217\u8868<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528\u4e58\u6cd5\u8fd0\u7b97\u7b26\u53ef\u4ee5\u5feb\u901f\u521b\u5efa\u4e00\u4e2a\u5305\u542b\u76f8\u540c\u5143\u7d20\u7684\u56fa\u5b9a\u957f\u5ea6\u5217\u8868\u3002\u4f8b\u5982\uff0c\u521b\u5efa\u4e00\u4e2a\u5305\u542b10\u4e2a0\u7684\u5217\u8868\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">zeros = [0] * 10<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u9700\u8981\u5feb\u901f\u521b\u5efa\u56fa\u5b9a\u957f\u5ea6\u4e14\u521d\u59cb\u503c\u76f8\u540c\u7684\u5217\u8868\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u521b\u5efa\u5d4c\u5957\u5217\u8868<\/h4>\n<\/p>\n<p><p>\u4e58\u6cd5\u8fd0\u7b97\u7b26\u8fd8\u53ef\u4ee5\u7528\u4e8e\u521b\u5efa\u5d4c\u5957\u5217\u8868\u3002\u4f8b\u5982\uff0c\u521b\u5efa\u4e00\u4e2a3&#215;3\u7684\u4e8c\u7ef4\u5217\u8868\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">matrix = [[0] * 3 for _ in range(3)]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u9700\u8981\u521b\u5efa\u56fa\u5b9a\u5927\u5c0f\u7684\u5d4c\u5957\u5217\u8868\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u4f7f\u7528\u5185\u7f6e\u51fd\u6570<\/h3>\n<\/p>\n<p><h4>1\u3001\u4f7f\u7528list()\u51fd\u6570<\/h4>\n<\/p>\n<p><p>Python\u5185\u7f6e\u7684list()\u51fd\u6570\u53ef\u4ee5\u5c06\u5176\u4ed6\u53ef\u8fed\u4ee3\u5bf9\u8c61\u8f6c\u6362\u4e3a\u5217\u8868\u3002\u4f8b\u5982\uff0c\u5c06\u4e00\u4e2a\u5143\u7ec4\u8f6c\u6362\u4e3a\u5217\u8868\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">tuple_data = (1, 2, 3)<\/p>\n<p>list_data = list(tuple_data)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u9700\u8981\u5c06\u5176\u4ed6\u7c7b\u578b\u7684\u53ef\u8fed\u4ee3\u5bf9\u8c61\u8f6c\u6362\u4e3a\u5217\u8868\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u4f7f\u7528range()\u51fd\u6570<\/h4>\n<\/p>\n<p><p>range()\u51fd\u6570\u751f\u6210\u4e00\u4e2a\u6574\u6570\u5e8f\u5217\uff0c\u53ef\u4ee5\u4e0elist()\u51fd\u6570\u7ed3\u5408\u4f7f\u7528\u751f\u6210\u5217\u8868\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">numbers = list(range(10))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u9700\u8981\u751f\u6210\u6570\u503c\u5e8f\u5217\u5e76\u8f6c\u6362\u4e3a\u5217\u8868\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u5176\u4ed6\u9ad8\u7ea7\u65b9\u6cd5<\/h3>\n<\/p>\n<p><h4>1\u3001\u4f7f\u7528\u751f\u6210\u5668\u8868\u8fbe\u5f0f<\/h4>\n<\/p>\n<p><p>\u751f\u6210\u5668\u8868\u8fbe\u5f0f\u7c7b\u4f3c\u4e8e\u5217\u8868\u63a8\u5bfc\u5f0f\uff0c\u4f46\u5b83\u8fd4\u56de\u4e00\u4e2a\u751f\u6210\u5668\u5bf9\u8c61\u800c\u4e0d\u662f\u5217\u8868\u3002\u53ef\u4ee5\u901a\u8fc7list()\u51fd\u6570\u5c06\u751f\u6210\u5668\u8f6c\u6362\u4e3a\u5217\u8868\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">gen = (i for i in range(10))<\/p>\n<p>numbers = list(gen)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u9700\u8981\u751f\u6210\u5668\u7684\u5ef6\u8fdf\u8ba1\u7b97\u7279\u6027\uff0c\u540c\u65f6\u53c8\u5e0c\u671b\u6700\u7ec8\u7ed3\u679c\u662f\u5217\u8868\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u4f7f\u7528itertools\u6a21\u5757<\/h4>\n<\/p>\n<p><p>Python\u7684itertools\u6a21\u5757\u63d0\u4f9b\u4e86\u8bb8\u591a\u751f\u6210\u5668\u51fd\u6570\uff0c\u53ef\u4ee5\u7528\u4e8e\u521b\u5efa\u590d\u6742\u7684\u5217\u8868\u3002\u4f8b\u5982\uff0c\u751f\u6210\u4e00\u4e2a\u65e0\u9650\u91cd\u590d\u7684\u5217\u8868\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import itertools<\/p>\n<p>infinite_list = list(itertools.islice(itertools.cycle([1, 2, 3]), 10))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u9700\u8981\u521b\u5efa\u590d\u6742\u7684\u751f\u6210\u5e8f\u5217\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>Python\u63d0\u4f9b\u4e86\u591a\u79cd\u7533\u8bf7\u5217\u8868\u7a7a\u95f4\u7684\u65b9\u6cd5\uff0c\u6bcf\u79cd\u65b9\u6cd5\u90fd\u6709\u5176\u4f18\u7f3a\u70b9\u548c\u9002\u7528\u573a\u666f\u3002\u76f4\u63a5\u521b\u5efa\u5217\u8868\u548c\u5217\u8868\u63a8\u5bfc\u5f0f\u662f\u6700\u5e38\u7528\u7684\u65b9\u6cd5\uff0c\u9002\u5408\u5927\u591a\u6570\u573a\u666f\u3002\u4f7f\u7528\u4e58\u6cd5\u8fd0\u7b97\u7b26\u53ef\u4ee5\u5feb\u901f\u521b\u5efa\u56fa\u5b9a\u957f\u5ea6\u7684\u5217\u8868\uff0c\u9002\u7528\u4e8e\u9700\u8981\u521d\u59cb\u5316\u56fa\u5b9a\u957f\u5ea6\u5217\u8868\u7684\u60c5\u51b5\u3002\u5185\u7f6e\u51fd\u6570list()\u548crange()\u7ed3\u5408\u4f7f\u7528\u53ef\u4ee5\u65b9\u4fbf\u5730\u751f\u6210\u6570\u503c\u5e8f\u5217\u5e76\u8f6c\u6362\u4e3a\u5217\u8868\u3002\u9ad8\u7ea7\u65b9\u6cd5\u5982\u751f\u6210\u5668\u8868\u8fbe\u5f0f\u548citertools\u6a21\u5757\u9002\u7528\u4e8e\u9700\u8981\u751f\u6210\u590d\u6742\u5e8f\u5217\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u5e94\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\uff0c\u4ee5\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u548c\u6267\u884c\u6548\u7387\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u521b\u5efa\u4e00\u4e2a\u7a7a\u5217\u8868\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u7b80\u5355\u7684\u8bed\u6cd5\u6765\u521b\u5efa\u4e00\u4e2a\u7a7a\u5217\u8868\u3002\u53ea\u9700\u4f7f\u7528\u4e00\u5bf9\u65b9\u62ec\u53f7\u5373\u53ef\uff0c\u4f8b\u5982\uff1a<code>my_list = []<\/code>\u3002\u8fd9\u6837\u5c31\u53ef\u4ee5\u5b9a\u4e49\u4e00\u4e2a\u7a7a\u5217\u8868\uff0c\u4e4b\u540e\u53ef\u4ee5\u901a\u8fc7<code>append()<\/code>\u65b9\u6cd5\u5411\u5217\u8868\u4e2d\u6dfb\u52a0\u5143\u7d20\u3002<\/p>\n<p><strong>Python\u4e2d\u5217\u8868\u7684\u6700\u5927\u957f\u5ea6\u662f\u591a\u5c11\uff1f<\/strong><br \/>Python\u4e2d\u7684\u5217\u8868\u6ca1\u6709\u56fa\u5b9a\u7684\u6700\u5927\u957f\u5ea6\uff0c\u5b83\u7684\u5927\u5c0f\u4ec5\u53d7\u53ef\u7528\u5185\u5b58\u7684\u9650\u5236\u3002\u968f\u7740\u5143\u7d20\u7684\u6dfb\u52a0\uff0c\u5217\u8868\u4f1a\u81ea\u52a8\u6269\u5c55\u4ee5\u5bb9\u7eb3\u65b0\u7684\u6570\u636e\uff0c\u56e0\u6b64\u7528\u6237\u65e0\u9700\u62c5\u5fc3\u624b\u52a8\u7ba1\u7406\u5217\u8868\u7684\u5927\u5c0f\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Python\u4e2d\u589e\u52a0\u5217\u8868\u7684\u5bb9\u91cf\uff1f<\/strong><br \/>Python\u7684\u5217\u8868\u4f1a\u81ea\u52a8\u7ba1\u7406\u5185\u5b58\uff0c\u56e0\u6b64\u7528\u6237\u4e0d\u9700\u8981\u624b\u52a8\u589e\u52a0\u5bb9\u91cf\u3002\u5f53\u6dfb\u52a0\u65b0\u5143\u7d20\u65f6\uff0cPython\u4f1a\u6839\u636e\u9700\u8981\u52a8\u6001\u8c03\u6574\u5185\u5b58\u3002\u5982\u679c\u4f60\u5e0c\u671b\u5728\u521b\u5efa\u5217\u8868\u65f6\u5c31\u9884\u8bbe\u4e00\u5b9a\u7684\u5bb9\u91cf\uff0c\u53ef\u4ee5\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u6216\u8005\u521d\u59cb\u5316\u4e00\u4e2a\u7279\u5b9a\u5927\u5c0f\u7684\u5217\u8868\uff0c\u4f8b\u5982\uff1a<code>my_list = [None] * 100<\/code>\uff0c\u8fd9\u5c06\u521b\u5efa\u4e00\u4e2a\u5305\u542b100\u4e2a<code>None<\/code>\u7684\u5217\u8868\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Python\u4e2d\u9ad8\u6548\u5730\u64cd\u4f5c\u5927\u578b\u5217\u8868\uff1f<\/strong><br \/>\u5bf9\u4e8e\u5927\u578b\u5217\u8868\u7684\u64cd\u4f5c\uff0c\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u548c\u5185\u5efa\u51fd\u6570\uff08\u5982<code>map()<\/code>\u548c<code>filter()<\/code>\uff09\u901a\u5e38\u80fd\u63d0\u9ad8\u6548\u7387\u3002\u6b64\u5916\uff0c\u8003\u8651\u4f7f\u7528NumPy\u5e93\u8fdb\u884c\u6570\u503c\u8ba1\u7b97\uff0c\u56e0\u4e3a\u5b83\u4e3a\u5927\u578b\u6570\u636e\u96c6\u63d0\u4f9b\u4e86\u66f4\u9ad8\u6548\u7684\u5b58\u50a8\u548c\u5904\u7406\u65b9\u5f0f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u7533\u8bf7\u5217\u8868\u7a7a\u95f4\u7684\u65b9\u6cd5\u5305\u62ec\u76f4\u63a5\u521b\u5efa\u5217\u8868\u3001\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u3001\u4f7f\u7528\u4e58\u6cd5\u8fd0\u7b97\u7b26\u521b\u5efa\u56fa\u5b9a\u957f\u5ea6\u7684\u5217\u8868\u3001\u4f7f\u7528\u5185\u7f6e\u51fd\u6570 [&hellip;]","protected":false},"author":3,"featured_media":1152202,"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\/1152188"}],"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=1152188"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1152188\/revisions"}],"predecessor-version":[{"id":1152205,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1152188\/revisions\/1152205"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1152202"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1152188"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1152188"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1152188"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}