{"id":1101455,"date":"2025-01-08T15:49:54","date_gmt":"2025-01-08T07:49:54","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1101455.html"},"modified":"2025-01-08T15:50:10","modified_gmt":"2025-01-08T07:50:10","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8python%e4%b9%9d%e4%b9%9d%e4%b9%98%e6%b3%95%e8%a1%a8-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1101455.html","title":{"rendered":"\u5982\u4f55\u5728python\u4e5d\u4e5d\u4e58\u6cd5\u8868"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25064215\/ff8175a6-e759-4f36-9eb6-cd966b3797bc.webp\" alt=\"\u5982\u4f55\u5728python\u4e5d\u4e5d\u4e58\u6cd5\u8868\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\u751f\u6210\u4e5d\u4e5d\u4e58\u6cd5\u8868\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u4e3b\u8981\u5305\u62ec\u4f7f\u7528\u5d4c\u5957\u5faa\u73af\u3001\u5217\u8868\u63a8\u5bfc\u5f0f\u3001\u683c\u5f0f\u5316\u8f93\u51fa\u7b49\u3002\u6700\u5e38\u7528\u7684\u65b9\u6cd5\u662f\u4f7f\u7528\u5d4c\u5957\u5faa\u73af\u6765\u751f\u6210\u5e76\u6253\u5370\u4e58\u6cd5\u8868\u3001\u4f7f\u7528\u5b57\u7b26\u4e32\u683c\u5f0f\u5316\u8f93\u51fa\u3002<\/strong> \u4e0b\u9762\u8be6\u7ec6\u63cf\u8ff0\u5982\u4f55\u4f7f\u7528\u5d4c\u5957\u5faa\u73af\u751f\u6210\u4e5d\u4e5d\u4e58\u6cd5\u8868\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u5d4c\u5957\u5faa\u73af\u751f\u6210\u4e5d\u4e5d\u4e58\u6cd5\u8868<\/h3>\n<\/p>\n<p><p>\u5d4c\u5957\u5faa\u73af\u662f\u751f\u6210\u4e5d\u4e5d\u4e58\u6cd5\u8868\u7684\u5e38\u7528\u65b9\u6cd5\u3002\u5728Python\u4e2d\uff0c\u4f7f\u7528\u4e24\u4e2a<code>for<\/code>\u5faa\u73af\uff0c\u4e00\u4e2a\u63a7\u5236\u884c\u6570\uff0c\u4e00\u4e2a\u63a7\u5236\u5217\u6570\uff0c\u901a\u8fc7\u5d4c\u5957\u5faa\u73af\u8f93\u51fa\u4e58\u6cd5\u8868\u3002<\/p>\n<\/p>\n<p><h4>\u793a\u4f8b\u4ee3\u7801\uff1a<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">for i in range(1, 10):<\/p>\n<p>    for j in range(1, i + 1):<\/p>\n<p>        print(f&quot;{j} * {i} = {i * j}&quot;, end=&quot;\\t&quot;)<\/p>\n<p>    print()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u4ee3\u7801\u89e3\u6790\uff1a<\/h4>\n<\/p>\n<ol>\n<li><strong>\u5916\u5c42\u5faa\u73af<\/strong>\uff1a<code>for i in range(1, 10)<\/code>\uff0c\u7528\u4e8e\u63a7\u5236\u884c\u6570\uff0c\u4ece1\u52309\u3002<\/li>\n<li><strong>\u5185\u5c42\u5faa\u73af<\/strong>\uff1a<code>for j in range(1, i + 1)<\/code>\uff0c\u7528\u4e8e\u63a7\u5236\u5217\u6570\uff0c\u6bcf\u4e00\u884c\u7684\u5217\u6570\u4e0e\u5f53\u524d\u884c\u6570\u76f8\u7b49\u3002<\/li>\n<li><strong>\u683c\u5f0f\u5316\u8f93\u51fa<\/strong>\uff1a<code>print(f&quot;{j} * {i} = {i * j}&quot;, end=&quot;\\t&quot;)<\/code>\uff0c\u4f7f\u7528f-string\u683c\u5f0f\u5316\u8f93\u51fa\u4e58\u6cd5\u7ed3\u679c\uff0c<code>end=&quot;\\t&quot;<\/code>\u8868\u793a\u6bcf\u4e2a\u7ed3\u679c\u4e4b\u95f4\u7528\u5236\u8868\u7b26\u5206\u9694\u3002<\/li>\n<li><strong>\u6362\u884c<\/strong>\uff1a<code>print()<\/code>\uff0c\u5185\u5c42\u5faa\u73af\u7ed3\u675f\u540e\u6362\u884c\u3002<\/li>\n<\/ol>\n<p><h3>\u4e8c\u3001\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u751f\u6210\u4e5d\u4e5d\u4e58\u6cd5\u8868<\/h3>\n<\/p>\n<p><p>\u5217\u8868\u63a8\u5bfc\u5f0f\u662f\u4e00\u79cd\u7b80\u6d01\u7684\u751f\u6210\u5217\u8868\u7684\u65b9\u6cd5\uff0c\u4e5f\u53ef\u4ee5\u7528\u6765\u751f\u6210\u4e5d\u4e5d\u4e58\u6cd5\u8868\u3002<\/p>\n<\/p>\n<p><h4>\u793a\u4f8b\u4ee3\u7801\uff1a<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">multiplication_table = [[f&quot;{j} * {i} = {i * j}&quot; for j in range(1, i + 1)] for i in range(1, 10)]<\/p>\n<p>for row in multiplication_table:<\/p>\n<p>    print(&quot;\\t&quot;.join(row))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u4ee3\u7801\u89e3\u6790\uff1a<\/h4>\n<\/p>\n<ol>\n<li><strong>\u751f\u6210\u4e58\u6cd5\u8868<\/strong>\uff1a<code>[[f&quot;{j} * {i} = {i * j}&quot; for j in range(1, i + 1)] for i in range(1, 10)]<\/code>\uff0c\u4f7f\u7528\u5d4c\u5957\u5217\u8868\u63a8\u5bfc\u5f0f\u751f\u6210\u4e58\u6cd5\u8868\u3002<\/li>\n<li><strong>\u6253\u5370\u4e58\u6cd5\u8868<\/strong>\uff1a<code>for row in multiplication_table: print(&quot;\\t&quot;.join(row))<\/code>\uff0c\u904d\u5386\u4e58\u6cd5\u8868\u7684\u6bcf\u4e00\u884c\uff0c\u7528\u5236\u8868\u7b26\u8fde\u63a5\u6bcf\u4e00\u884c\u7684\u5143\u7d20\u5e76\u6253\u5370\u3002<\/li>\n<\/ol>\n<p><h3>\u4e09\u3001\u4f7f\u7528\u51fd\u6570\u751f\u6210\u4e5d\u4e5d\u4e58\u6cd5\u8868<\/h3>\n<\/p>\n<p><p>\u5c06\u751f\u6210\u4e5d\u4e5d\u4e58\u6cd5\u8868\u7684\u903b\u8f91\u5c01\u88c5\u6210\u4e00\u4e2a\u51fd\u6570\uff0c\u66f4\u52a0\u6a21\u5757\u5316\u548c\u53ef\u91cd\u7528\u3002<\/p>\n<\/p>\n<p><h4>\u793a\u4f8b\u4ee3\u7801\uff1a<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">def print_multiplication_table():<\/p>\n<p>    for i in range(1, 10):<\/p>\n<p>        for j in range(1, i + 1):<\/p>\n<p>            print(f&quot;{j} * {i} = {i * j}&quot;, end=&quot;\\t&quot;)<\/p>\n<p>        print()<\/p>\n<p>print_multiplication_table()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u4ee3\u7801\u89e3\u6790\uff1a<\/h4>\n<\/p>\n<ol>\n<li><strong>\u5b9a\u4e49\u51fd\u6570<\/strong>\uff1a<code>def print_multiplication_table():<\/code>\uff0c\u5b9a\u4e49\u4e00\u4e2a\u51fd\u6570\u6765\u751f\u6210\u4e5d\u4e5d\u4e58\u6cd5\u8868\u3002<\/li>\n<li><strong>\u6253\u5370\u4e58\u6cd5\u8868<\/strong>\uff1a\u51fd\u6570\u5185\u90e8\u4f7f\u7528\u5d4c\u5957\u5faa\u73af\u751f\u6210\u548c\u6253\u5370\u4e58\u6cd5\u8868\u3002<\/li>\n<li><strong>\u8c03\u7528\u51fd\u6570<\/strong>\uff1a<code>print_multiplication_table()<\/code>\uff0c\u8c03\u7528\u51fd\u6570\u751f\u6210\u5e76\u6253\u5370\u4e58\u6cd5\u8868\u3002<\/li>\n<\/ol>\n<p><h3>\u56db\u3001\u4f7f\u7528\u5b57\u7b26\u4e32\u683c\u5f0f\u5316\u8f93\u51fa<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528\u5b57\u7b26\u4e32\u7684<code>format<\/code>\u65b9\u6cd5\uff0c\u53ef\u4ee5\u66f4\u7075\u6d3b\u5730\u63a7\u5236\u8f93\u51fa\u683c\u5f0f\u3002<\/p>\n<\/p>\n<p><h4>\u793a\u4f8b\u4ee3\u7801\uff1a<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">for i in range(1, 10):<\/p>\n<p>    for j in range(1, i + 1):<\/p>\n<p>        print(&quot;{0} * {1} = {2}&quot;.format(j, i, i * j), end=&quot;\\t&quot;)<\/p>\n<p>    print()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u4ee3\u7801\u89e3\u6790\uff1a<\/h4>\n<\/p>\n<ol>\n<li><strong>\u5916\u5c42\u5faa\u73af<\/strong>\uff1a<code>for i in range(1, 10)<\/code>\uff0c\u7528\u4e8e\u63a7\u5236\u884c\u6570\uff0c\u4ece1\u52309\u3002<\/li>\n<li><strong>\u5185\u5c42\u5faa\u73af<\/strong>\uff1a<code>for j in range(1, i + 1)<\/code>\uff0c\u7528\u4e8e\u63a7\u5236\u5217\u6570\uff0c\u6bcf\u4e00\u884c\u7684\u5217\u6570\u4e0e\u5f53\u524d\u884c\u6570\u76f8\u7b49\u3002<\/li>\n<li><strong>\u683c\u5f0f\u5316\u8f93\u51fa<\/strong>\uff1a<code>print(&quot;{0} * {1} = {2}&quot;.format(j, i, i * j), end=&quot;\\t&quot;)<\/code>\uff0c\u4f7f\u7528<code>format<\/code>\u65b9\u6cd5\u683c\u5f0f\u5316\u8f93\u51fa\u4e58\u6cd5\u7ed3\u679c\uff0c<code>end=&quot;\\t&quot;<\/code>\u8868\u793a\u6bcf\u4e2a\u7ed3\u679c\u4e4b\u95f4\u7528\u5236\u8868\u7b26\u5206\u9694\u3002<\/li>\n<li><strong>\u6362\u884c<\/strong>\uff1a<code>print()<\/code>\uff0c\u5185\u5c42\u5faa\u73af\u7ed3\u675f\u540e\u6362\u884c\u3002<\/li>\n<\/ol>\n<p><h3>\u4e94\u3001\u5c06\u4e5d\u4e5d\u4e58\u6cd5\u8868\u5199\u5165\u6587\u4ef6<\/h3>\n<\/p>\n<p><p>\u5c06\u751f\u6210\u7684\u4e5d\u4e5d\u4e58\u6cd5\u8868\u5199\u5165\u6587\u4ef6\uff0c\u53ef\u4ee5\u66f4\u65b9\u4fbf\u5730\u8fdb\u884c\u4fdd\u5b58\u548c\u67e5\u770b\u3002<\/p>\n<\/p>\n<p><h4>\u793a\u4f8b\u4ee3\u7801\uff1a<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">with open(&quot;multiplication_table.txt&quot;, &quot;w&quot;) as file:<\/p>\n<p>    for i in range(1, 10):<\/p>\n<p>        for j in range(1, i + 1):<\/p>\n<p>            file.write(f&quot;{j} * {i} = {i * j}\\t&quot;)<\/p>\n<p>        file.write(&quot;\\n&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u4ee3\u7801\u89e3\u6790\uff1a<\/h4>\n<\/p>\n<ol>\n<li><strong>\u6253\u5f00\u6587\u4ef6<\/strong>\uff1a<code>with open(&quot;multiplication_table.txt&quot;, &quot;w&quot;) as file<\/code>\uff0c\u6253\u5f00\u4e00\u4e2a\u6587\u4ef6\u7528\u4e8e\u5199\u5165\u3002<\/li>\n<li><strong>\u751f\u6210\u4e58\u6cd5\u8868<\/strong>\uff1a\u4f7f\u7528\u5d4c\u5957\u5faa\u73af\u751f\u6210\u4e58\u6cd5\u8868\u3002<\/li>\n<li><strong>\u5199\u5165\u6587\u4ef6<\/strong>\uff1a\u4f7f\u7528<code>file.write<\/code>\u65b9\u6cd5\u5c06\u4e58\u6cd5\u7ed3\u679c\u5199\u5165\u6587\u4ef6\uff0c\u7528\u5236\u8868\u7b26\u5206\u9694\u6bcf\u4e2a\u7ed3\u679c\uff0c\u884c\u5c3e\u6362\u884c\u3002<\/li>\n<\/ol>\n<p><h3>\u516d\u3001\u4f7f\u7528Pandas\u5e93\u751f\u6210\u4e5d\u4e5d\u4e58\u6cd5\u8868<\/h3>\n<\/p>\n<p><p>Pandas\u5e93\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u6570\u636e\u5206\u6790\u5e93\uff0c\u4e5f\u53ef\u4ee5\u7528\u6765\u751f\u6210\u548c\u5c55\u793a\u4e5d\u4e5d\u4e58\u6cd5\u8868\u3002<\/p>\n<\/p>\n<p><h4>\u793a\u4f8b\u4ee3\u7801\uff1a<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>data = [[f&quot;{j} * {i} = {i * j}&quot; for j in range(1, i + 1)] for i in range(1, 10)]<\/p>\n<p>df = pd.DataFrame(data)<\/p>\n<p>print(df.to_string(index=False, header=False))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u4ee3\u7801\u89e3\u6790\uff1a<\/h4>\n<\/p>\n<ol>\n<li><strong>\u5bfc\u5165Pandas\u5e93<\/strong>\uff1a<code>import pandas as pd<\/code>\uff0c\u5bfc\u5165Pandas\u5e93\u3002<\/li>\n<li><strong>\u751f\u6210\u6570\u636e<\/strong>\uff1a<code>data = [[f&quot;{j} * {i} = {i * j}&quot; for j in range(1, i + 1)] for i in range(1, 10)]<\/code>\uff0c\u4f7f\u7528\u5d4c\u5957\u5217\u8868\u63a8\u5bfc\u5f0f\u751f\u6210\u4e58\u6cd5\u8868\u6570\u636e\u3002<\/li>\n<li><strong>\u521b\u5efaDataFrame<\/strong>\uff1a<code>df = pd.DataFrame(data)<\/code>\uff0c\u5c06\u6570\u636e\u8f6c\u6362\u4e3aDataFrame\u5bf9\u8c61\u3002<\/li>\n<li><strong>\u6253\u5370DataFrame<\/strong>\uff1a<code>print(df.to_string(index=False, header=False))<\/code>\uff0c\u5c06DataFrame\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u5e76\u6253\u5370\uff0c\u4e0d\u663e\u793a\u7d22\u5f15\u548c\u5217\u540d\u3002<\/li>\n<\/ol>\n<p><h3>\u4e03\u3001\u4f7f\u7528NumPy\u5e93\u751f\u6210\u4e5d\u4e5d\u4e58\u6cd5\u8868<\/h3>\n<\/p>\n<p><p>NumPy\u5e93\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u6570\u503c\u8ba1\u7b97\u5e93\uff0c\u4e5f\u53ef\u4ee5\u7528\u6765\u751f\u6210\u4e5d\u4e5d\u4e58\u6cd5\u8868\u3002<\/p>\n<\/p>\n<p><h4>\u793a\u4f8b\u4ee3\u7801\uff1a<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>table = np.zeros((9, 9), dtype=int)<\/p>\n<p>for i in range(1, 10):<\/p>\n<p>    for j in range(1, i + 1):<\/p>\n<p>        table[i-1][j-1] = i * j<\/p>\n<p>for i in range(9):<\/p>\n<p>    for j in range(i + 1):<\/p>\n<p>        print(f&quot;{j+1} * {i+1} = {table[i][j]}&quot;, end=&quot;\\t&quot;)<\/p>\n<p>    print()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u4ee3\u7801\u89e3\u6790\uff1a<\/h4>\n<\/p>\n<ol>\n<li><strong>\u5bfc\u5165NumPy\u5e93<\/strong>\uff1a<code>import numpy as np<\/code>\uff0c\u5bfc\u5165NumPy\u5e93\u3002<\/li>\n<li><strong>\u521b\u5efa\u6570\u7ec4<\/strong>\uff1a<code>table = np.zeros((9, 9), dtype=int)<\/code>\uff0c\u521b\u5efa\u4e00\u4e2a9&#215;9\u7684\u5168\u96f6\u6570\u7ec4\u3002<\/li>\n<li><strong>\u586b\u5145\u6570\u7ec4<\/strong>\uff1a\u4f7f\u7528\u5d4c\u5957\u5faa\u73af\u586b\u5145\u4e58\u6cd5\u7ed3\u679c\u3002<\/li>\n<li><strong>\u6253\u5370\u6570\u7ec4<\/strong>\uff1a\u4f7f\u7528\u5d4c\u5957\u5faa\u73af\u6253\u5370\u4e58\u6cd5\u7ed3\u679c\u3002<\/li>\n<\/ol>\n<p><h3>\u516b\u3001\u4f7f\u7528\u683c\u5f0f\u5316\u6a21\u5757\u751f\u6210\u4e5d\u4e5d\u4e58\u6cd5\u8868<\/h3>\n<\/p>\n<p><p>Python\u7684<code>texttable<\/code>\u6a21\u5757\u53ef\u4ee5\u5e2e\u52a9\u683c\u5f0f\u5316\u8868\u683c\u8f93\u51fa\u3002<\/p>\n<\/p>\n<p><h4>\u793a\u4f8b\u4ee3\u7801\uff1a<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">from texttable import Texttable<\/p>\n<p>table = Texttable()<\/p>\n<p>for i in range(1, 10):<\/p>\n<p>    row = [f&quot;{j} * {i} = {i * j}&quot; for j in range(1, i + 1)]<\/p>\n<p>    table.add_row(row)<\/p>\n<p>print(table.draw())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u4ee3\u7801\u89e3\u6790\uff1a<\/h4>\n<\/p>\n<ol>\n<li><strong>\u5bfc\u5165\u6a21\u5757<\/strong>\uff1a<code>from texttable import Texttable<\/code>\uff0c\u5bfc\u5165<code>texttable<\/code>\u6a21\u5757\u3002<\/li>\n<li><strong>\u521b\u5efa\u8868\u683c\u5bf9\u8c61<\/strong>\uff1a<code>table = Texttable()<\/code>\uff0c\u521b\u5efa\u4e00\u4e2a\u8868\u683c\u5bf9\u8c61\u3002<\/li>\n<li><strong>\u586b\u5145\u8868\u683c<\/strong>\uff1a\u4f7f\u7528\u5d4c\u5957\u5faa\u73af\u586b\u5145\u8868\u683c\u7684\u6bcf\u4e00\u884c\u3002<\/li>\n<li><strong>\u6253\u5370\u8868\u683c<\/strong>\uff1a<code>print(table.draw())<\/code>\uff0c\u7ed8\u5236\u5e76\u6253\u5370\u8868\u683c\u3002<\/li>\n<\/ol>\n<p><h3>\u7ed3\u8bba<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7\u4e0a\u8ff0\u65b9\u6cd5\uff0c\u53ef\u4ee5\u7075\u6d3b\u5730\u5728Python\u4e2d\u751f\u6210\u4e5d\u4e5d\u4e58\u6cd5\u8868\u3002\u4e0d\u540c\u7684\u65b9\u6cd5\u5404\u6709\u4f18\u52a3\uff0c\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u53ef\u4ee5\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u548c\u53ef\u7ef4\u62a4\u6027\u3002\u5d4c\u5957\u5faa\u73af\u662f\u6700\u57fa\u672c\u7684\u65b9\u6cd5\uff0c\u9002\u5408\u521d\u5b66\u8005\u4f7f\u7528\uff1b\u5217\u8868\u63a8\u5bfc\u5f0f\u548c\u51fd\u6570\u5c01\u88c5\u63d0\u9ad8\u4e86\u4ee3\u7801\u7684\u7b80\u6d01\u6027\u548c\u53ef\u91cd\u7528\u6027\uff1bPandas\u548cNumPy\u5e93\u9002\u5408\u6570\u636e\u5206\u6790\u548c\u6570\u503c\u8ba1\u7b97\u7684\u573a\u666f\uff1b\u683c\u5f0f\u5316\u6a21\u5757\u9002\u5408\u9700\u8981\u7f8e\u89c2\u8f93\u51fa\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u751f\u6210\u4e5d\u4e5d\u4e58\u6cd5\u8868\u7684\u4ee3\u7801\uff1f<\/strong><br \/>\u8981\u751f\u6210\u4e5d\u4e5d\u4e58\u6cd5\u8868\uff0c\u53ef\u4ee5\u4f7f\u7528\u5d4c\u5957\u5faa\u73af\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<pre><code class=\"language-python\">for i in range(1, 10):\n    for j in range(1, i + 1):\n        print(f&quot;{j} x {i} = {i * j}&quot;, end=&quot;\\t&quot;)\n    print()\n<\/code><\/pre>\n<p>\u8fd0\u884c\u8fd9\u6bb5\u4ee3\u7801\u540e\uff0c\u60a8\u5c06\u770b\u5230\u683c\u5f0f\u5316\u7684\u4e5d\u4e5d\u4e58\u6cd5\u8868\u8f93\u51fa\u3002<\/p>\n<p><strong>\u4f7f\u7528Python\u751f\u6210\u4e5d\u4e5d\u4e58\u6cd5\u8868\u65f6\uff0c\u6709\u54ea\u4e9b\u5e38\u89c1\u7684\u9519\u8bef\uff1f<\/strong><br \/>\u4e00\u4e9b\u5e38\u89c1\u7684\u9519\u8bef\u5305\u62ec\u5faa\u73af\u8303\u56f4\u8bbe\u7f6e\u4e0d\u5f53\uff0c\u5bfc\u81f4\u4e58\u6cd5\u8868\u4e0d\u5b8c\u6574\uff0c\u6216\u8005\u5728\u6253\u5370\u8f93\u51fa\u65f6\u6ca1\u6709\u4f7f\u7528<code>end<\/code>\u53c2\u6570\uff0c\u5bfc\u81f4\u8f93\u51fa\u5185\u5bb9\u4e0d\u6362\u884c\u3002\u786e\u4fdd\u4f7f\u7528\u6b63\u786e\u7684\u8303\u56f4\u548c\u683c\u5f0f\u5316\u8f93\u51fa\uff0c\u53ef\u4ee5\u6709\u6548\u907f\u514d\u8fd9\u4e9b\u95ee\u9898\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Python\u4e2d\u7f8e\u5316\u4e5d\u4e5d\u4e58\u6cd5\u8868\u7684\u8f93\u51fa\u683c\u5f0f\uff1f<\/strong><br \/>\u8981\u7f8e\u5316\u8f93\u51fa\u683c\u5f0f\uff0c\u53ef\u4ee5\u4f7f\u7528\u5b57\u7b26\u4e32\u683c\u5f0f\u5316\u65b9\u6cd5\u6765\u5bf9\u9f50\u6570\u5b57\u3002\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-python\">for i in range(1, 10):\n    for j in range(1, i + 1):\n        print(f&quot;{j} x {i} = {i * j:2}&quot;, end=&quot;\\t&quot;)\n    print()\n<\/code><\/pre>\n<p>\u5728\u8fd9\u4e2a\u4ee3\u7801\u4e2d\uff0c<code>:2<\/code>\u7528\u4e8e\u786e\u4fdd\u6bcf\u4e2a\u4e58\u79ef\u81f3\u5c11\u5360\u7528\u4e24\u4e2a\u5b57\u7b26\u7684\u5bbd\u5ea6\uff0c\u4ece\u800c\u4f7f\u8f93\u51fa\u66f4\u52a0\u6574\u9f50\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u751f\u6210\u4e5d\u4e5d\u4e58\u6cd5\u8868\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u4e3b\u8981\u5305\u62ec\u4f7f\u7528\u5d4c\u5957\u5faa\u73af\u3001\u5217\u8868\u63a8\u5bfc\u5f0f\u3001\u683c\u5f0f\u5316\u8f93\u51fa\u7b49\u3002\u6700\u5e38\u7528\u7684\u65b9\u6cd5\u662f\u4f7f\u7528 [&hellip;]","protected":false},"author":3,"featured_media":1101487,"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\/1101455"}],"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=1101455"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1101455\/revisions"}],"predecessor-version":[{"id":1101493,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1101455\/revisions\/1101493"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1101487"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1101455"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1101455"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1101455"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}