{"id":1158727,"date":"2025-01-13T18:44:16","date_gmt":"2025-01-13T10:44:16","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1158727.html"},"modified":"2025-01-13T18:44:18","modified_gmt":"2025-01-13T10:44:18","slug":"python%e5%a6%82%e4%bd%95%e5%ae%9e%e7%8e%b0%e5%be%aa%e7%8e%af%e6%ac%a1%e6%95%b0","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1158727.html","title":{"rendered":"python\u5982\u4f55\u5b9e\u73b0\u5faa\u73af\u6b21\u6570"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25200617\/27c05b49-a747-4642-a0f7-2665068d3ab4.webp\" alt=\"python\u5982\u4f55\u5b9e\u73b0\u5faa\u73af\u6b21\u6570\" \/><\/p>\n<p><p> <strong>Python\u5b9e\u73b0\u5faa\u73af\u6b21\u6570\u7684\u65b9\u6cd5\u6709\uff1a\u4f7f\u7528<code>for<\/code>\u5faa\u73af\u3001\u4f7f\u7528<code>while<\/code>\u5faa\u73af\u3001\u4f7f\u7528<code>itertools<\/code>\u6a21\u5757\u3001\u4f7f\u7528\u751f\u6210\u5668\u3002<\/strong>\u5176\u4e2d\uff0c\u6700\u5e38\u7528\u7684\u662f<code>for<\/code>\u5faa\u73af\u548c<code>while<\/code>\u5faa\u73af\uff0c\u6b64\u5916<code>itertools<\/code>\u6a21\u5757\u548c\u751f\u6210\u5668\u4e5f\u63d0\u4f9b\u4e86\u66f4\u9ad8\u7ea7\u7684\u5faa\u73af\u63a7\u5236\u65b9\u5f0f\u3002\u4e0b\u9762\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u51e0\u79cd\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><p><strong>for\u5faa\u73af<\/strong>\u662fPython\u4e2d\u6700\u5e38\u89c1\u7684\u5faa\u73af\u8bed\u53e5\u4e4b\u4e00\uff0c\u901a\u5e38\u7528\u4e8e\u904d\u5386\u4e00\u4e2a\u5e8f\u5217\uff08\u5982\u5217\u8868\u3001\u5143\u7ec4\u3001\u5b57\u7b26\u4e32\uff09\u6216\u4f7f\u7528<code>range()<\/code>\u51fd\u6570\u6307\u5b9a\u5faa\u73af\u7684\u6b21\u6570\u3002<strong>while\u5faa\u73af<\/strong>\u5219\u5728\u6761\u4ef6\u4e3a\u771f\u65f6\u53cd\u590d\u6267\u884c\u4ee3\u7801\u5757\uff0c\u9002\u7528\u4e8e\u9700\u8981\u672a\u77e5\u6b21\u6570\u5faa\u73af\u7684\u60c5\u51b5\u3002<strong>itertools\u6a21\u5757<\/strong>\u63d0\u4f9b\u4e86\u591a\u79cd\u7528\u4e8e\u9ad8\u6548\u5faa\u73af\u7684\u5de5\u5177\uff0c\u53ef\u4ee5\u5b9e\u73b0\u590d\u6742\u7684\u5faa\u73af\u903b\u8f91\u3002<strong>\u751f\u6210\u5668<\/strong>\u5219\u662f\u4e00\u79cd\u7279\u6b8a\u7684\u8fed\u4ee3\u5668\uff0c\u53ef\u4ee5\u5728\u5faa\u73af\u8fc7\u7a0b\u4e2d\u52a8\u6001\u4ea7\u751f\u503c\u3002\u4e0b\u9762\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u51e0\u79cd\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><h2>\u4e00\u3001for\u5faa\u73af<\/h2>\n<\/p>\n<p><h3>\u57fa\u672c\u7528\u6cd5<\/h3>\n<\/p>\n<p><p><code>for<\/code>\u5faa\u73af\u662fPython\u4e2d\u6700\u5e38\u89c1\u7684\u5faa\u73af\u7ed3\u6784\u4e4b\u4e00\uff0c\u7528\u4e8e\u904d\u5386\u4e00\u4e2a\u5e8f\u5217\uff08\u5982\u5217\u8868\u3001\u5143\u7ec4\u3001\u5b57\u7b26\u4e32\uff09\u6216\u4f7f\u7528<code>range()<\/code>\u51fd\u6570\u6307\u5b9a\u5faa\u73af\u7684\u6b21\u6570\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">for i in range(5):<\/p>\n<p>    print(i)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u5c06\u8f93\u51fa0\u52304\u7684\u6570\u5b57\uff0c\u56e0\u4e3a<code>range(5)<\/code>\u751f\u6210\u4e86\u4e00\u4e2a\u4ece0\u52304\u7684\u5e8f\u5217\u3002<\/p>\n<\/p>\n<p><h3>\u904d\u5386\u5217\u8868<\/h3>\n<\/p>\n<p><p><code>for<\/code>\u5faa\u73af\u4e5f\u53ef\u4ee5\u7528\u4e8e\u904d\u5386\u5217\u8868\u4e2d\u7684\u5143\u7d20\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">fruits = [&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;]<\/p>\n<p>for fruit in fruits:<\/p>\n<p>    print(fruit)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u5c06\u8f93\u51fa\u5217\u8868\u4e2d\u7684\u6bcf\u4e00\u4e2a\u6c34\u679c\u540d\u79f0\u3002<\/p>\n<\/p>\n<p><h3>\u4f7f\u7528enumerate()<\/h3>\n<\/p>\n<p><p>\u5728\u904d\u5386\u5217\u8868\u65f6\uff0c\u6709\u65f6\u6211\u4eec\u9700\u8981\u77e5\u9053\u5143\u7d20\u7684\u7d22\u5f15\uff0c\u53ef\u4ee5\u4f7f\u7528<code>enumerate()<\/code>\u51fd\u6570\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">fruits = [&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;]<\/p>\n<p>for index, fruit in enumerate(fruits):<\/p>\n<p>    print(index, fruit)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u4e0d\u4ec5\u8f93\u51fa\u6c34\u679c\u540d\u79f0\uff0c\u8fd8\u8f93\u51fa\u5b83\u4eec\u5728\u5217\u8868\u4e2d\u7684\u7d22\u5f15\u3002<\/p>\n<\/p>\n<p><h3>\u5d4c\u5957for\u5faa\u73af<\/h3>\n<\/p>\n<p><p><code>for<\/code>\u5faa\u73af\u4e5f\u53ef\u4ee5\u5d4c\u5957\u4f7f\u7528\uff0c\u7528\u4e8e\u904d\u5386\u591a\u7ef4\u7ed3\u6784\uff08\u5982\u4e8c\u7ef4\u5217\u8868\uff09\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">matrix = [<\/p>\n<p>    [1, 2, 3],<\/p>\n<p>    [4, 5, 6],<\/p>\n<p>    [7, 8, 9]<\/p>\n<p>]<\/p>\n<p>for row in matrix:<\/p>\n<p>    for element in row:<\/p>\n<p>        print(element, end=&quot; &quot;)<\/p>\n<p>    print()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u8f93\u51fa\u4e00\u4e2a3&#215;3\u7684\u77e9\u9635\u3002<\/p>\n<\/p>\n<p><h2>\u4e8c\u3001while\u5faa\u73af<\/h2>\n<\/p>\n<p><h3>\u57fa\u672c\u7528\u6cd5<\/h3>\n<\/p>\n<p><p><code>while<\/code>\u5faa\u73af\u5728\u6307\u5b9a\u6761\u4ef6\u4e3a\u771f\u65f6\u53cd\u590d\u6267\u884c\u4ee3\u7801\u5757\uff0c\u9002\u7528\u4e8e\u9700\u8981\u672a\u77e5\u6b21\u6570\u5faa\u73af\u7684\u60c5\u51b5\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">i = 0<\/p>\n<p>while i &lt; 5:<\/p>\n<p>    print(i)<\/p>\n<p>    i += 1<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u5c06\u8f93\u51fa0\u52304\u7684\u6570\u5b57\u3002<\/p>\n<\/p>\n<p><h3>\u65e0\u9650\u5faa\u73af<\/h3>\n<\/p>\n<p><p><code>while<\/code>\u5faa\u73af\u53ef\u4ee5\u5f88\u5bb9\u6613\u5730\u53d8\u6210\u65e0\u9650\u5faa\u73af\uff0c\u5982\u679c\u6761\u4ef6\u59cb\u7ec8\u4e3a\u771f\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">while True:<\/p>\n<p>    print(&quot;This is an infinite loop&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u901a\u5e38\u9700\u8981\u4f7f\u7528<code>break<\/code>\u8bed\u53e5\u6765\u9000\u51fa\u5faa\u73af\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">i = 0<\/p>\n<p>while True:<\/p>\n<p>    print(i)<\/p>\n<p>    i += 1<\/p>\n<p>    if i == 5:<\/p>\n<p>        break<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u8f93\u51fa0\u52304\u7684\u6570\u5b57\uff0c\u7136\u540e\u9000\u51fa\u5faa\u73af\u3002<\/p>\n<\/p>\n<p><h3>\u4f7f\u7528else<\/h3>\n<\/p>\n<p><p><code>while<\/code>\u5faa\u73af\u4e5f\u53ef\u4ee5\u548c<code>else<\/code>\u8bed\u53e5\u7ed3\u5408\u4f7f\u7528\uff0c\u5f53\u5faa\u73af\u6761\u4ef6\u4e3a\u5047\u65f6\u6267\u884c<code>else<\/code>\u5757\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">i = 0<\/p>\n<p>while i &lt; 5:<\/p>\n<p>    print(i)<\/p>\n<p>    i += 1<\/p>\n<p>else:<\/p>\n<p>    print(&quot;Loop ended&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u8f93\u51fa0\u52304\u7684\u6570\u5b57\uff0c\u7136\u540e\u8f93\u51fa&quot;Loop ended&quot;\u3002<\/p>\n<\/p>\n<p><h2>\u4e09\u3001itertools\u6a21\u5757<\/h2>\n<\/p>\n<p><h3>\u57fa\u672c\u7528\u6cd5<\/h3>\n<\/p>\n<p><p><code>itertools<\/code>\u6a21\u5757\u63d0\u4f9b\u4e86\u591a\u79cd\u7528\u4e8e\u9ad8\u6548\u5faa\u73af\u7684\u5de5\u5177\uff0c\u53ef\u4ee5\u5b9e\u73b0\u590d\u6742\u7684\u5faa\u73af\u903b\u8f91\u3002\u4f8b\u5982\uff0c<code>itertools.count()<\/code>\u751f\u6210\u4e00\u4e2a\u65e0\u9650\u9012\u589e\u7684\u6574\u6570\u5e8f\u5217\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import itertools<\/p>\n<p>for i in itertools.count(0, 2):<\/p>\n<p>    if i &gt; 10:<\/p>\n<p>        break<\/p>\n<p>    print(i)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u8f93\u51fa0\u523010\u7684\u5076\u6570\u3002<\/p>\n<\/p>\n<p><h3>\u4f7f\u7528cycle()<\/h3>\n<\/p>\n<p><p><code>itertools.cycle()<\/code>\u53ef\u4ee5\u5faa\u73af\u904d\u5386\u4e00\u4e2a\u5e8f\u5217\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import itertools<\/p>\n<p>colors = [&quot;red&quot;, &quot;green&quot;, &quot;blue&quot;]<\/p>\n<p>for color in itertools.cycle(colors):<\/p>\n<p>    print(color)<\/p>\n<p>    if color == &quot;blue&quot;:<\/p>\n<p>        break<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u8f93\u51fa\u7ea2\u8272\u3001\u7eff\u8272\u548c\u84dd\u8272\uff0c\u7136\u540e\u9000\u51fa\u5faa\u73af\u3002<\/p>\n<\/p>\n<p><h3>\u4f7f\u7528repeat()<\/h3>\n<\/p>\n<p><p><code>itertools.repeat()<\/code>\u53ef\u4ee5\u91cd\u590d\u4e00\u4e2a\u5143\u7d20\u6307\u5b9a\u7684\u6b21\u6570\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import itertools<\/p>\n<p>for item in itertools.repeat(&quot;hello&quot;, 3):<\/p>\n<p>    print(item)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u8f93\u51fa&quot;hello&quot;\u4e09\u6b21\u3002<\/p>\n<\/p>\n<p><h2>\u56db\u3001\u751f\u6210\u5668<\/h2>\n<\/p>\n<p><h3>\u57fa\u672c\u7528\u6cd5<\/h3>\n<\/p>\n<p><p>\u751f\u6210\u5668\u662f\u4e00\u79cd\u7279\u6b8a\u7684\u8fed\u4ee3\u5668\uff0c\u53ef\u4ee5\u5728\u5faa\u73af\u8fc7\u7a0b\u4e2d\u52a8\u6001\u4ea7\u751f\u503c\uff0c\u4f7f\u7528<code>yield<\/code>\u5173\u952e\u5b57\u5b9a\u4e49\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def countdown(n):<\/p>\n<p>    while n &gt; 0:<\/p>\n<p>        yield n<\/p>\n<p>        n -= 1<\/p>\n<p>for i in countdown(5):<\/p>\n<p>    print(i)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u8f93\u51fa5\u52301\u7684\u6570\u5b57\u3002<\/p>\n<\/p>\n<p><h3>\u65e0\u9650\u751f\u6210\u5668<\/h3>\n<\/p>\n<p><p>\u751f\u6210\u5668\u4e5f\u53ef\u4ee5\u7528\u4e8e\u521b\u5efa\u65e0\u9650\u5e8f\u5217\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def infinite_sequence():<\/p>\n<p>    num = 0<\/p>\n<p>    while True:<\/p>\n<p>        yield num<\/p>\n<p>        num += 1<\/p>\n<p>for i in infinite_sequence():<\/p>\n<p>    if i &gt; 10:<\/p>\n<p>        break<\/p>\n<p>    print(i)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u8f93\u51fa0\u523010\u7684\u6570\u5b57\u3002<\/p>\n<\/p>\n<p><h3>\u4e0e\u5176\u4ed6\u5faa\u73af\u7ed3\u5408<\/h3>\n<\/p>\n<p><p>\u751f\u6210\u5668\u53ef\u4ee5\u4e0e\u5176\u4ed6\u5faa\u73af\u7ed3\u6784\u7ed3\u5408\u4f7f\u7528\uff0c\u5b9e\u73b0\u66f4\u590d\u6742\u7684\u5faa\u73af\u903b\u8f91\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def even_numbers(max_num):<\/p>\n<p>    num = 0<\/p>\n<p>    while num &lt;= max_num:<\/p>\n<p>        if num % 2 == 0:<\/p>\n<p>            yield num<\/p>\n<p>        num += 1<\/p>\n<p>for even in even_numbers(10):<\/p>\n<p>    print(even)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u8f93\u51fa0\u523010\u7684\u5076\u6570\u3002<\/p>\n<\/p>\n<p><h2>\u4e94\u3001\u7ed3\u5408\u4f7f\u7528<\/h2>\n<\/p>\n<p><h3>for\u4e0ewhile\u7ed3\u5408<\/h3>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c<code>for<\/code>\u5faa\u73af\u548c<code>while<\/code>\u5faa\u73af\u53ef\u4ee5\u7ed3\u5408\u4f7f\u7528\uff0c\u5b9e\u73b0\u66f4\u590d\u6742\u7684\u5faa\u73af\u63a7\u5236\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">i = 0<\/p>\n<p>for j in range(5):<\/p>\n<p>    while i &lt; j:<\/p>\n<p>        print(f&quot;i: {i}, j: {j}&quot;)<\/p>\n<p>        i += 1<\/p>\n<p>    i = 0<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u5c55\u793a\u4e86\u5982\u4f55\u5728<code>for<\/code>\u5faa\u73af\u5185\u4f7f\u7528<code>while<\/code>\u5faa\u73af\u3002<\/p>\n<\/p>\n<p><h3>itertools\u4e0e\u751f\u6210\u5668\u7ed3\u5408<\/h3>\n<\/p>\n<p><p><code>itertools<\/code>\u6a21\u5757\u548c\u751f\u6210\u5668\u53ef\u4ee5\u7ed3\u5408\u4f7f\u7528\uff0c\u5b9e\u73b0\u66f4\u9ad8\u6548\u7684\u5faa\u73af\u63a7\u5236\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import itertools<\/p>\n<p>def count_up_to(n):<\/p>\n<p>    for i in itertools.count(0):<\/p>\n<p>        if i &gt; n:<\/p>\n<p>            break<\/p>\n<p>        yield i<\/p>\n<p>for num in count_up_to(5):<\/p>\n<p>    print(num)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u8f93\u51fa0\u52305\u7684\u6570\u5b57\u3002<\/p>\n<\/p>\n<p><h3>\u5d4c\u5957\u5faa\u73af\u4e0e\u751f\u6210\u5668\u7ed3\u5408<\/h3>\n<\/p>\n<p><p>\u751f\u6210\u5668\u4e5f\u53ef\u4ee5\u4e0e\u5d4c\u5957\u5faa\u73af\u7ed3\u5408\u4f7f\u7528\uff0c\u5b9e\u73b0\u66f4\u590d\u6742\u7684\u6570\u636e\u7ed3\u6784\u904d\u5386\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def flatten_list(nested_list):<\/p>\n<p>    for sublist in nested_list:<\/p>\n<p>        for item in sublist:<\/p>\n<p>            yield item<\/p>\n<p>nested_list = [[1, 2, 3], [4, 5], [6, 7, 8, 9]]<\/p>\n<p>for num in flatten_list(nested_list):<\/p>\n<p>    print(num)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u8f93\u51fa\u5d4c\u5957\u5217\u8868\u4e2d\u7684\u6240\u6709\u5143\u7d20\u3002<\/p>\n<\/p>\n<p><h2>\u516d\u3001\u6027\u80fd\u4f18\u5316<\/h2>\n<\/p>\n<p><h3>\u4f7f\u7528list comprehension<\/h3>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\uff08list comprehension\uff09\u53ef\u4ee5\u63d0\u9ad8\u5faa\u73af\u6027\u80fd\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">squares = [x2 for x in range(10)]<\/p>\n<p>print(squares)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u751f\u62100\u52309\u7684\u5e73\u65b9\u6570\u5217\u8868\uff0c\u6bd4\u4f20\u7edf\u7684<code>for<\/code>\u5faa\u73af\u66f4\u9ad8\u6548\u3002<\/p>\n<\/p>\n<p><h3>\u4f7f\u7528\u751f\u6210\u5668\u8868\u8fbe\u5f0f<\/h3>\n<\/p>\n<p><p>\u751f\u6210\u5668\u8868\u8fbe\u5f0f\u6bd4\u5217\u8868\u63a8\u5bfc\u5f0f\u66f4\u8282\u7701\u5185\u5b58\uff0c\u9002\u7528\u4e8e\u5904\u7406\u5927\u6570\u636e\u96c6\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">squares = (x2 for x in range(10))<\/p>\n<p>for square in squares:<\/p>\n<p>    print(square)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u751f\u62100\u52309\u7684\u5e73\u65b9\u6570\uff0c\u4f46\u4e0d\u4f1a\u4e00\u6b21\u6027\u5c06\u5b83\u4eec\u5b58\u50a8\u5728\u5185\u5b58\u4e2d\u3002<\/p>\n<\/p>\n<p><h3>\u4f7f\u7528\u5185\u7f6e\u51fd\u6570<\/h3>\n<\/p>\n<p><p>Python\u5185\u7f6e\u7684\u8bb8\u591a\u51fd\u6570\uff08\u5982<code>sum()<\/code>\u3001<code>min()<\/code>\u3001<code>max()<\/code>\u7b49\uff09\u6bd4\u624b\u52a8\u7f16\u5199\u7684\u5faa\u73af\u66f4\u9ad8\u6548\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">numbers = [1, 2, 3, 4, 5]<\/p>\n<p>print(sum(numbers))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u8ba1\u7b97\u5217\u8868\u4e2d\u6240\u6709\u5143\u7d20\u7684\u548c\uff0c\u6bd4\u624b\u52a8\u7f16\u5199<code>for<\/code>\u5faa\u73af\u66f4\u9ad8\u6548\u3002<\/p>\n<\/p>\n<p><h3>\u4f7f\u7528\u591a\u7ebf\u7a0b\u4e0e\u591a\u8fdb\u7a0b<\/h3>\n<\/p>\n<p><p>\u5bf9\u4e8eCPU\u5bc6\u96c6\u578b\u4efb\u52a1\uff0c\u53ef\u4ee5\u4f7f\u7528\u591a\u7ebf\u7a0b\u6216\u591a\u8fdb\u7a0b\u6765\u63d0\u9ad8\u6027\u80fd\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import concurrent.futures<\/p>\n<p>def compute_square(n):<\/p>\n<p>    return n2<\/p>\n<p>numbers = [1, 2, 3, 4, 5]<\/p>\n<p>with concurrent.futures.ThreadPoolExecutor() as executor:<\/p>\n<p>    results = executor.map(compute_square, numbers)<\/p>\n<p>for result in results:<\/p>\n<p>    print(result)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u4f7f\u7528\u7ebf\u7a0b\u6c60\u5e76\u884c\u8ba1\u7b97\u5e73\u65b9\u6570\u3002<\/p>\n<\/p>\n<p><h3>\u4f7f\u7528NumPy<\/h3>\n<\/p>\n<p><p>\u5bf9\u4e8e\u6570\u503c\u8ba1\u7b97\uff0c\u4f7f\u7528NumPy\u5e93\u53ef\u4ee5\u663e\u8457\u63d0\u9ad8\u6027\u80fd\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>numbers = np.array([1, 2, 3, 4, 5])<\/p>\n<p>squares = numbers  2<\/p>\n<p>print(squares)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u4f7f\u7528NumPy\u5e93\u8ba1\u7b97\u5e73\u65b9\u6570\uff0c\u6bd4\u7eafPython\u5b9e\u73b0\u66f4\u9ad8\u6548\u3002<\/p>\n<\/p>\n<p><h2>\u4e03\u3001\u9519\u8bef\u5904\u7406<\/h2>\n<\/p>\n<p><h3>\u6355\u83b7\u5f02\u5e38<\/h3>\n<\/p>\n<p><p>\u5728\u5faa\u73af\u4e2d\u5904\u7406\u53ef\u80fd\u7684\u5f02\u5e38\uff0c\u53ef\u4ee5\u63d0\u9ad8\u4ee3\u7801\u7684\u5065\u58ee\u6027\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">numbers = [1, 2, &#39;three&#39;, 4, 5]<\/p>\n<p>for num in numbers:<\/p>\n<p>    try:<\/p>\n<p>        print(num2)<\/p>\n<p>    except TypeError:<\/p>\n<p>        print(f&quot;Cannot compute square of {num}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u5728\u9047\u5230\u975e\u6570\u5b57\u5143\u7d20\u65f6\u4e0d\u4f1a\u5d29\u6e83\uff0c\u800c\u662f\u8f93\u51fa\u9519\u8bef\u4fe1\u606f\u3002<\/p>\n<\/p>\n<p><h3>\u4f7f\u7528finally<\/h3>\n<\/p>\n<p><p><code>finally<\/code>\u5757\u53ef\u4ee5\u786e\u4fdd\u65e0\u8bba\u662f\u5426\u53d1\u751f\u5f02\u5e38\uff0c\u90fd\u4f1a\u6267\u884c\u67d0\u4e9b\u4ee3\u7801\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">numbers = [1, 2, &#39;three&#39;, 4, 5]<\/p>\n<p>for num in numbers:<\/p>\n<p>    try:<\/p>\n<p>        print(num2)<\/p>\n<p>    except TypeError:<\/p>\n<p>        print(f&quot;Cannot compute square of {num}&quot;)<\/p>\n<p>    finally:<\/p>\n<p>        print(f&quot;Processed {num}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u5728\u5904\u7406\u6bcf\u4e2a\u5143\u7d20\u540e\u90fd\u4f1a\u8f93\u51fa&quot;Processed&quot;\u4fe1\u606f\u3002<\/p>\n<\/p>\n<p><h3>\u81ea\u5b9a\u4e49\u5f02\u5e38<\/h3>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u81ea\u5b9a\u4e49\u5f02\u5e38\u53ef\u4ee5\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u548c\u53ef\u7ef4\u62a4\u6027\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">class NegativeNumberError(Exception):<\/p>\n<p>    pass<\/p>\n<p>def compute_square(n):<\/p>\n<p>    if n &lt; 0:<\/p>\n<p>        r<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>se NegativeNumberError(f&quot;Cannot compute square of negative number: {n}&quot;)<\/p>\n<p>    return n2<\/p>\n<p>numbers = [1, -2, 3, -4, 5]<\/p>\n<p>for num in numbers:<\/p>\n<p>    try:<\/p>\n<p>        print(compute_square(num))<\/p>\n<p>    except NegativeNumberError as e:<\/p>\n<p>        print(e)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u5728\u9047\u5230\u8d1f\u6570\u65f6\u629b\u51fa\u81ea\u5b9a\u4e49\u5f02\u5e38\u5e76\u8f93\u51fa\u9519\u8bef\u4fe1\u606f\u3002<\/p>\n<\/p>\n<p><h2>\u516b\u3001\u8c03\u8bd5\u6280\u5de7<\/h2>\n<\/p>\n<p><h3>\u4f7f\u7528print\u8c03\u8bd5<\/h3>\n<\/p>\n<p><p>\u5728\u5faa\u73af\u4e2d\u63d2\u5165<code>print()<\/code>\u8bed\u53e5\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u8c03\u8bd5\u4ee3\u7801\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">numbers = [1, 2, 3, 4, 5]<\/p>\n<p>for num in numbers:<\/p>\n<p>    print(f&quot;Processing {num}&quot;)<\/p>\n<p>    print(num2)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u8f93\u51fa\u6bcf\u4e2a\u5143\u7d20\u7684\u5904\u7406\u4fe1\u606f\u548c\u5e73\u65b9\u6570\u3002<\/p>\n<\/p>\n<p><h3>\u4f7f\u7528\u65ad\u70b9<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528\u8c03\u8bd5\u5668\u8bbe\u7f6e\u65ad\u70b9\uff0c\u53ef\u4ee5\u9010\u6b65\u6267\u884c\u4ee3\u7801\u5e76\u68c0\u67e5\u53d8\u91cf\u503c\u3002\u4f8b\u5982\uff0c\u5728Python IDE\uff08\u5982PyCharm\u3001VSCode\uff09\u4e2d\u8bbe\u7f6e\u65ad\u70b9\u5e76\u8fd0\u884c\u8c03\u8bd5\u6a21\u5f0f\u3002<\/p>\n<\/p>\n<p><h3>\u4f7f\u7528logging\u6a21\u5757<\/h3>\n<\/p>\n<p><p><code>logging<\/code>\u6a21\u5757\u6bd4<code>print()<\/code>\u66f4\u7075\u6d3b\uff0c\u9002\u7528\u4e8e\u590d\u6742\u7684\u8c03\u8bd5\u9700\u6c42\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import logging<\/p>\n<p>logging.basicConfig(level=logging.DEBUG)<\/p>\n<p>numbers = [1, 2, 3, 4, 5]<\/p>\n<p>for num in numbers:<\/p>\n<p>    logging.debug(f&quot;Processing {num}&quot;)<\/p>\n<p>    logging.debug(num2)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u8f93\u51fa\u6bcf\u4e2a\u5143\u7d20\u7684\u5904\u7406\u4fe1\u606f\u548c\u5e73\u65b9\u6570\uff0c\u4f46\u53ef\u4ee5\u901a\u8fc7\u8c03\u6574\u65e5\u5fd7\u7ea7\u522b\u63a7\u5236\u8f93\u51fa\u5185\u5bb9\u3002<\/p>\n<\/p>\n<p><h2>\u4e5d\u3001\u5b9e\u9645\u5e94\u7528<\/h2>\n<\/p>\n<p><h3>\u6570\u636e\u5904\u7406<\/h3>\n<\/p>\n<p><p>\u5faa\u73af\u5728\u6570\u636e\u5904\u7406\u4e2d\u975e\u5e38\u5e38\u89c1\u3002\u4f8b\u5982\uff0c\u904d\u5386CSV\u6587\u4ef6\u7684\u6bcf\u4e00\u884c\u5e76\u5904\u7406\u6570\u636e\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import csv<\/p>\n<p>with open(&#39;data.csv&#39;, newline=&#39;&#39;) as csvfile:<\/p>\n<p>    reader = csv.reader(csvfile)<\/p>\n<p>    for row in reader:<\/p>\n<p>        print(row)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u8bfb\u53d6\u5e76\u8f93\u51faCSV\u6587\u4ef6\u7684\u6bcf\u4e00\u884c\u3002<\/p>\n<\/p>\n<p><h3>\u6587\u4ef6\u64cd\u4f5c<\/h3>\n<\/p>\n<p><p>\u5faa\u73af\u5728\u6587\u4ef6\u64cd\u4f5c\u4e2d\u4e5f\u5f88\u5e38\u89c1\u3002\u4f8b\u5982\uff0c\u9010\u884c\u8bfb\u53d6\u6587\u4ef6\u5e76\u5904\u7406\u6bcf\u4e00\u884c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">with open(&#39;data.txt&#39;) as file:<\/p>\n<p>    for line in file:<\/p>\n<p>        print(line.strip())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u9010\u884c\u8bfb\u53d6\u5e76\u8f93\u51fa\u6587\u4ef6\u5185\u5bb9\u3002<\/p>\n<\/p>\n<p><h3>\u7f51\u7edc\u8bf7\u6c42<\/h3>\n<\/p>\n<p><p>\u5faa\u73af\u5728\u7f51\u7edc\u8bf7\u6c42\u4e2d\u7528\u4e8e\u5904\u7406\u591a\u4e2a\u8bf7\u6c42\u3002\u4f8b\u5982\uff0c\u53d1\u9001\u591a\u4e2aHTTP\u8bf7\u6c42\u5e76\u5904\u7406\u54cd\u5e94\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import requests<\/p>\n<p>urls = [&#39;http:\/\/example.com&#39;, &#39;http:\/\/example.org&#39;, &#39;http:\/\/example.net&#39;]<\/p>\n<p>for url in urls:<\/p>\n<p>    response = requests.get(url)<\/p>\n<p>    print(response.status_code)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u53d1\u9001\u591a\u4e2aHTTP\u8bf7\u6c42\u5e76\u8f93\u51fa\u54cd\u5e94\u72b6\u6001\u7801\u3002<\/p>\n<\/p>\n<p><h3>\u722c\u866b\u5e94\u7528<\/h3>\n<\/p>\n<p><p>\u5faa\u73af\u5728\u722c\u866b\u5e94\u7528\u4e2d\u7528\u4e8e\u904d\u5386\u7f51\u9875\u5e76\u63d0\u53d6\u6570\u636e\u3002\u4f8b\u5982\uff0c\u6293\u53d6\u591a\u4e2a\u7f51\u9875\u7684\u5185\u5bb9\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import requests<\/p>\n<p>from bs4 import BeautifulSoup<\/p>\n<p>urls = [&#39;http:\/\/example.com&#39;, &#39;http:\/\/example.org&#39;, &#39;http:\/\/example.net&#39;]<\/p>\n<p>for url in urls:<\/p>\n<p>    response = requests.get(url)<\/p>\n<p>    soup = BeautifulSoup(response.content, &#39;html.parser&#39;)<\/p>\n<p>    print(soup.title.string)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u6293\u53d6\u591a\u4e2a\u7f51\u9875\u5e76\u8f93\u51fa\u9875\u9762\u6807\u9898\u3002<\/p>\n<\/p>\n<p><h3>\u6e38\u620f\u5f00\u53d1<\/h3>\n<\/p>\n<p><p>\u5faa\u73af\u5728\u6e38\u620f\u5f00\u53d1\u4e2d\u7528\u4e8e\u66f4\u65b0\u6e38\u620f\u72b6\u6001\u548c\u5904\u7406\u7528\u6237\u8f93\u5165\u3002\u4f8b\u5982\uff0c\u6e38\u620f\u4e3b\u5faa\u73af\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">running = True<\/p>\n<p>while running:<\/p>\n<p>    for event in pygame.event.get():<\/p>\n<p>        if event.type == pygame.QUIT:<\/p>\n<p>            running = False<\/p>\n<p>    # \u66f4\u65b0\u6e38\u620f\u72b6\u6001<\/p>\n<p>    # \u7ed8\u5236\u6e38\u620f\u753b\u9762<\/p>\n<p>    pygame.display.flip()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u5b9e\u73b0\u4e86\u4e00\u4e2a\u7b80\u5355\u7684\u6e38\u620f\u4e3b\u5faa\u73af\u3002<\/p>\n<\/p>\n<p><h3>\u6570\u636e\u5206\u6790<\/h3>\n<\/p>\n<p><p>\u5faa\u73af\u5728\u6570\u636e\u5206\u6790\u4e2d\u7528\u4e8e\u5904\u7406\u548c\u5206\u6790\u6570\u636e\u3002\u4f8b\u5982\uff0c\u8ba1\u7b97\u6570\u636e\u96c6\u7684\u5e73\u5747\u503c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">data = [1, 2, 3, 4, 5]<\/p>\n<p>total = 0<\/p>\n<p>for num in data:<\/p>\n<p>    total += num<\/p>\n<p>average = total \/ len(data)<\/p>\n<p>print(average)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u8ba1\u7b97\u6570\u636e\u96c6\u7684\u5e73\u5747\u503c\u3002<\/p>\n<\/p>\n<p><h3>\u56fe\u50cf\u5904\u7406<\/h3>\n<\/p>\n<p><p>\u5faa\u73af\u5728\u56fe\u50cf\u5904\u7406\u4e2d\u7528\u4e8e\u5904\u7406\u50cf\u7d20\u6570\u636e\u3002\u4f8b\u5982\uff0c\u9010\u884c\u5904\u7406\u56fe\u50cf\u50cf\u7d20\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from PIL import Image<\/p>\n<p>image = Image.open(&#39;image.jpg&#39;)<\/p>\n<p>pixels = image.load()<\/p>\n<p>for y in range(image.height):<\/p>\n<p>    for x in range(image.width):<\/p>\n<p>        r, g, b = pixels[x, y]<\/p>\n<p>        pixels[x, y] = (255 - r, 255 - g, 255 - b)<\/p>\n<p>image.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u53cd\u8f6c\u56fe\u50cf\u7684\u989c\u8272\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u4e0a\u8ff0\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u5230Python\u63d0\u4f9b\u4e86\u591a\u79cd\u65b9\u6cd5\u5b9e\u73b0\u5faa\u73af\uff0c\u5e76\u4e14\u6bcf\u79cd\u65b9\u6cd5\u90fd\u6709\u5176\u72ec\u7279\u7684\u4f18\u70b9\u548c\u9002\u7528\u573a\u666f\u3002\u719f\u7ec3\u638c\u63e1\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u53ef\u4ee5\u4f7f\u6211\u4eec\u5728\u7f16\u5199Python\u4ee3\u7801\u65f6\u66f4\u52a0\u7075\u6d3b\u548c\u9ad8\u6548\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u8bbe\u7f6e\u5faa\u73af\u7684\u6b21\u6570\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>for<\/code>\u5faa\u73af\u548c<code>range()<\/code>\u51fd\u6570\u6765\u8bbe\u7f6e\u5faa\u73af\u7684\u6b21\u6570\u3002\u4f8b\u5982\uff0c<code>for i in range(5):<\/code>\u5c06\u6267\u884c5\u6b21\u5faa\u73af\u3002<code>range(5)<\/code>\u751f\u6210\u4ece0\u52304\u7684\u6574\u6570\u5e8f\u5217\uff0c\u56e0\u6b64\u5faa\u73af\u4f53\u5185\u7684\u4ee3\u7801\u5c06\u88ab\u6267\u884c5\u6b21\u3002\u7528\u6237\u53ef\u4ee5\u8c03\u6574<code>range()<\/code>\u51fd\u6570\u4e2d\u7684\u53c2\u6570\uff0c\u4ee5\u8bbe\u7f6e\u6240\u9700\u7684\u5faa\u73af\u6b21\u6570\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u5982\u4f55\u5b9e\u73b0\u65e0\u9650\u5faa\u73af\uff1f<\/strong><br \/>\u65e0\u9650\u5faa\u73af\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528<code>while True:<\/code>\u8bed\u53e5\u6765\u5b9e\u73b0\u3002\u6b64\u7ed3\u6784\u5c06\u6301\u7eed\u6267\u884c\u5faa\u73af\u4f53\u5185\u7684\u4ee3\u7801\uff0c\u76f4\u5230\u901a\u8fc7<code>break<\/code>\u8bed\u53e5\u6216\u5f02\u5e38\u6765\u7ec8\u6b62\u5faa\u73af\u3002\u4f7f\u7528\u65e0\u9650\u5faa\u73af\u65f6\uff0c\u52a1\u5fc5\u8981\u786e\u4fdd\u6709\u9002\u5f53\u7684\u6761\u4ef6\u6765\u8df3\u51fa\u5faa\u73af\uff0c\u4ee5\u907f\u514d\u7a0b\u5e8f\u65e0\u54cd\u5e94\u6216\u8fc7\u5ea6\u5360\u7528\u7cfb\u7edf\u8d44\u6e90\u3002<\/p>\n<p><strong>\u5982\u4f55\u63a7\u5236\u5faa\u73af\u7684\u6267\u884c\u6761\u4ef6\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>while<\/code>\u5faa\u73af\u7ed3\u5408\u6761\u4ef6\u5224\u65ad\u6765\u63a7\u5236\u5faa\u73af\u7684\u6267\u884c\u3002\u4f8b\u5982\uff0c<code>while count &lt; 10:<\/code>\u5c06\u4f1a\u5728<code>count<\/code>\u5c0f\u4e8e10\u65f6\u6301\u7eed\u6267\u884c\u5faa\u73af\u3002\u901a\u8fc7\u5728\u5faa\u73af\u4f53\u5185\u66f4\u65b0<code>count<\/code>\u7684\u503c\uff0c\u53ef\u4ee5\u5b9e\u73b0\u5bf9\u5faa\u73af\u6b21\u6570\u7684\u7075\u6d3b\u63a7\u5236\uff0c\u9002\u7528\u4e8e\u9700\u8981\u52a8\u6001\u8c03\u6574\u5faa\u73af\u6b21\u6570\u7684\u573a\u666f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u5b9e\u73b0\u5faa\u73af\u6b21\u6570\u7684\u65b9\u6cd5\u6709\uff1a\u4f7f\u7528for\u5faa\u73af\u3001\u4f7f\u7528while\u5faa\u73af\u3001\u4f7f\u7528itertools\u6a21\u5757\u3001\u4f7f\u7528\u751f\u6210\u5668\u3002 [&hellip;]","protected":false},"author":3,"featured_media":1158733,"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\/1158727"}],"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=1158727"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1158727\/revisions"}],"predecessor-version":[{"id":1158737,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1158727\/revisions\/1158737"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1158733"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1158727"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1158727"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1158727"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}