{"id":1129231,"date":"2025-01-08T20:27:46","date_gmt":"2025-01-08T12:27:46","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1129231.html"},"modified":"2025-01-08T20:27:49","modified_gmt":"2025-01-08T12:27:49","slug":"%e5%a6%82%e4%bd%95%e7%94%a8python%e5%81%9a%e5%87%ba%e4%b9%9d%e4%b9%9d%e4%b9%98%e6%b3%95%e8%a1%a8","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1129231.html","title":{"rendered":"\u5982\u4f55\u7528python\u505a\u51fa\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\/25095713\/3af8f4b6-018f-4c6a-8156-997e8b1d5694.webp\" alt=\"\u5982\u4f55\u7528python\u505a\u51fa\u4e5d\u4e5d\u4e58\u6cd5\u8868\" \/><\/p>\n<p><p> <strong>\u5982\u4f55\u7528Python\u505a\u51fa\u4e5d\u4e5d\u4e58\u6cd5\u8868<\/strong><\/p>\n<\/p>\n<p><p>\u7528Python\u5236\u4f5c\u4e5d\u4e5d\u4e58\u6cd5\u8868\u975e\u5e38\u7b80\u5355\uff0c\u53ea\u9700\u5229\u7528\u5faa\u73af\u7ed3\u6784\u548c\u5b57\u7b26\u4e32\u683c\u5f0f\u5316\u5373\u53ef\u5b9e\u73b0\u3002<strong>\u901a\u8fc7\u5d4c\u5957\u5faa\u73af\u3001\u4f7f\u7528\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u3001\u5229\u7528print\u51fd\u6570<\/strong>\uff0c\u6211\u4eec\u53ef\u4ee5\u8fc5\u901f\u751f\u6210\u4e00\u4e2a\u6574\u6d01\u7684\u4e5d\u4e5d\u4e58\u6cd5\u8868\u3002\u4e0b\u9762\u8be6\u7ec6\u4ecb\u7ecd\u5176\u4e2d\u4e00\u79cd\u5b9e\u73b0\u65b9\u5f0f\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528\u5d4c\u5957\u5faa\u73af\u751f\u6210\u4e5d\u4e5d\u4e58\u6cd5\u8868<\/h3>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u5d4c\u5957\u5faa\u73af\u662f\u5b9e\u73b0\u4e5d\u4e5d\u4e58\u6cd5\u8868\u7684\u5173\u952e\u3002\u901a\u8fc7\u5916\u5c42\u5faa\u73af\u63a7\u5236\u884c\uff0c\u5185\u5c42\u5faa\u73af\u63a7\u5236\u5217\uff0c\u6211\u4eec\u53ef\u4ee5\u9010\u4e2a\u751f\u6210\u4e58\u79ef\u3002<\/p>\n<\/p>\n<p><h4>1.1 \u5d4c\u5957\u5faa\u73af\u7684\u57fa\u7840<\/h4>\n<\/p>\n<p><p>\u5d4c\u5957\u5faa\u73af\u662f\u6307\u5728\u4e00\u4e2a\u5faa\u73af\u4f53\u5185\u518d\u5d4c\u5957\u4e00\u4e2a\u5faa\u73af\u3002\u5bf9\u4e8e\u4e5d\u4e5d\u4e58\u6cd5\u8868\u6765\u8bf4\uff0c\u5916\u5c42\u5faa\u73af\u4ece1\u52309\uff0c\u8868\u793a\u884c\u6570\uff1b\u5185\u5c42\u5faa\u73af\u4e5f\u4ece1\u52309\uff0c\u8868\u793a\u5217\u6570\u3002\u6bcf\u4e2a\u5185\u5c42\u5faa\u73af\u7684\u4ea7\u51fa\u90fd\u662f\u4e24\u4e2a\u6570\u7684\u4e58\u79ef\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">for i in range(1, 10):  # \u5916\u5c42\u5faa\u73af\u63a7\u5236\u884c\u6570<\/p>\n<p>    for j in range(1, 10):  # \u5185\u5c42\u5faa\u73af\u63a7\u5236\u5217\u6570<\/p>\n<p>        print(f&quot;{i}*{j}={i*j}&quot;, end=&quot;\\t&quot;)  # \u4f7f\u7528\u5236\u8868\u7b26\\t\u5bf9\u9f50\u8f93\u51fa<\/p>\n<p>    print()  # \u6bcf\u884c\u7ed3\u675f\u540e\u6362\u884c<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>1.2 \u683c\u5f0f\u5316\u8f93\u51fa<\/h4>\n<\/p>\n<p><p>\u4e3a\u4e86\u4f7f\u4e58\u6cd5\u8868\u770b\u8d77\u6765\u66f4\u6574\u9f50\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u3002\u8fd9\u6837\u6bcf\u4e2a\u4e58\u79ef\u90fd\u4f1a\u5360\u7528\u56fa\u5b9a\u7684\u7a7a\u95f4\uff0c\u4fdd\u8bc1\u5217\u5bf9\u9f50\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">for i in range(1, 10):<\/p>\n<p>    for j in range(1, 10):<\/p>\n<p>        print(f&quot;{i}*{j}={i*j:2}&quot;, end=&quot;  &quot;)  # :2\u8868\u793a\u6570\u5b57\u5360\u4e24\u4f4d<\/p>\n<p>    print()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e8c\u3001\u5229\u7528\u51fd\u6570\u5c01\u88c5\u4e5d\u4e5d\u4e58\u6cd5\u8868<\/h3>\n<\/p>\n<p><p>\u4e3a\u4e86\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u548c\u590d\u7528\u6027\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u751f\u6210\u4e5d\u4e5d\u4e58\u6cd5\u8868\u7684\u4ee3\u7801\u5c01\u88c5\u6210\u4e00\u4e2a\u51fd\u6570\u3002<\/p>\n<\/p>\n<p><h4>2.1 \u5b9a\u4e49\u51fd\u6570<\/h4>\n<\/p>\n<p><p>\u51fd\u6570\u662f\u7ec4\u7ec7\u4ee3\u7801\u7684\u4e00\u79cd\u65b9\u5f0f\uff0c\u53ef\u4ee5\u5c06\u529f\u80fd\u76f8\u4f3c\u7684\u4ee3\u7801\u5757\u5c01\u88c5\u5728\u4e00\u8d77\u3002\u5b9a\u4e49\u4e00\u4e2a\u751f\u6210\u4e5d\u4e5d\u4e58\u6cd5\u8868\u7684\u51fd\u6570\uff0c\u4f7f\u4ee3\u7801\u7ed3\u6784\u66f4\u6e05\u6670\u3002<\/p>\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, 10):<\/p>\n<p>            print(f&quot;{i}*{j}={i*j:2}&quot;, end=&quot;  &quot;)<\/p>\n<p>        print()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2.2 \u8c03\u7528\u51fd\u6570<\/h4>\n<\/p>\n<p><p>\u5728\u9700\u8981\u751f\u6210\u4e5d\u4e5d\u4e58\u6cd5\u8868\u65f6\uff0c\u53ea\u9700\u8c03\u7528\u8be5\u51fd\u6570\u5373\u53ef\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">print_multiplication_table()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001\u4e5d\u4e5d\u4e58\u6cd5\u8868\u7684\u591a\u79cd\u5c55\u793a\u65b9\u5f0f<\/h3>\n<\/p>\n<p><p>\u9664\u4e86\u57fa\u672c\u7684\u884c\u5217\u5c55\u793a\u65b9\u5f0f\uff0c\u6211\u4eec\u8fd8\u53ef\u4ee5\u7528\u5176\u4ed6\u65b9\u5f0f\u5c55\u793a\u4e5d\u4e5d\u4e58\u6cd5\u8868\uff0c\u4f8b\u5982\u5012\u5e8f\u5c55\u793a\u3001\u5bf9\u89d2\u7ebf\u5c55\u793a\u7b49\u3002<\/p>\n<\/p>\n<p><h4>3.1 \u5012\u5e8f\u5c55\u793a<\/h4>\n<\/p>\n<p><p>\u5012\u5e8f\u5c55\u793a\u4e58\u6cd5\u8868\uff0c\u53ef\u4ee5\u4f7f\u7528range\u51fd\u6570\u7684\u7b2c\u4e09\u4e2a\u53c2\u6570\uff0c\u6307\u5b9a\u6b65\u957f\u4e3a-1\uff0c\u4ece\u800c\u5b9e\u73b0\u4ece\u5927\u5230\u5c0f\u7684\u5faa\u73af\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def print_reverse_multiplication_table():<\/p>\n<p>    for i in range(9, 0, -1):<\/p>\n<p>        for j in range(9, 0, -1):<\/p>\n<p>            print(f&quot;{i}*{j}={i*j:2}&quot;, end=&quot;  &quot;)<\/p>\n<p>        print()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3.2 \u5bf9\u89d2\u7ebf\u5c55\u793a<\/h4>\n<\/p>\n<p><p>\u5bf9\u89d2\u7ebf\u5c55\u793a\u4e5d\u4e5d\u4e58\u6cd5\u8868\u53ef\u4ee5\u589e\u52a0\u4e00\u4e9b\u6761\u4ef6\u5224\u65ad\uff0c\u786e\u4fdd\u53ea\u6253\u5370\u5bf9\u89d2\u7ebf\u4e0a\u7684\u4e58\u79ef\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def print_diagonal_multiplication_table():<\/p>\n<p>    for i in range(1, 10):<\/p>\n<p>        for j in range(1, 10):<\/p>\n<p>            if i == j:<\/p>\n<p>                print(f&quot;{i}*{j}={i*j:2}&quot;, end=&quot;  &quot;)<\/p>\n<p>            else:<\/p>\n<p>                print(&quot;      &quot;, end=&quot;  &quot;)  # \u5bf9\u9f50\u7a7a\u767d\u90e8\u5206<\/p>\n<p>        print()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u4e5d\u4e5d\u4e58\u6cd5\u8868\u7684\u56fe\u5f62\u5316\u754c\u9762<\/h3>\n<\/p>\n<p><p>\u9664\u4e86\u5728\u63a7\u5236\u53f0\u8f93\u51fa\uff0c\u6211\u4eec\u8fd8\u53ef\u4ee5\u4f7f\u7528\u56fe\u5f62\u5316\u754c\u9762\u5e93\uff08\u5982Tkinter\uff09\u6765\u751f\u6210\u4e5d\u4e5d\u4e58\u6cd5\u8868\u3002<\/p>\n<\/p>\n<p><h4>4.1 \u57fa\u7840\u7684Tkinter\u5e94\u7528<\/h4>\n<\/p>\n<p><p>Tkinter\u662fPython\u7684\u6807\u51c6GUI\u5e93\uff0c\u53ef\u4ee5\u7528\u6765\u521b\u5efa\u56fe\u5f62\u754c\u9762\u5e94\u7528\u3002\u9996\u5148\uff0c\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684Tkinter\u7a97\u53e3\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import tkinter as tk<\/p>\n<p>root = tk.Tk()<\/p>\n<p>root.title(&quot;\u4e5d\u4e5d\u4e58\u6cd5\u8868&quot;)<\/p>\n<p>root.geometry(&quot;400x400&quot;)<\/p>\n<p>label = tk.Label(root, text=&quot;\u4e5d\u4e5d\u4e58\u6cd5\u8868&quot;, font=(&quot;Arial&quot;, 16))<\/p>\n<p>label.pack()<\/p>\n<p>root.m<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>nloop()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>4.2 \u5728Tkinter\u7a97\u53e3\u4e2d\u663e\u793a\u4e5d\u4e5d\u4e58\u6cd5\u8868<\/h4>\n<\/p>\n<p><p>\u5728Tkinter\u7a97\u53e3\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Label\u7ec4\u4ef6\u6765\u663e\u793a\u4e5d\u4e5d\u4e58\u6cd5\u8868\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def display_multiplication_table():<\/p>\n<p>    text = &quot;&quot;<\/p>\n<p>    for i in range(1, 10):<\/p>\n<p>        for j in range(1, 10):<\/p>\n<p>            text += f&quot;{i}*{j}={i*j:2}  &quot;<\/p>\n<p>        text += &quot;\\n&quot;<\/p>\n<p>    return text<\/p>\n<p>label = tk.Label(root, text=display_multiplication_table(), font=(&quot;Arial&quot;, 12))<\/p>\n<p>label.pack()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e94\u3001\u4e5d\u4e5d\u4e58\u6cd5\u8868\u7684\u5e94\u7528\u5b9e\u4f8b<\/h3>\n<\/p>\n<p><p>\u4e5d\u4e5d\u4e58\u6cd5\u8868\u4e0d\u4ec5\u4ec5\u662f\u4e00\u4e2a\u6570\u5b66\u7ec3\u4e60\u5de5\u5177\uff0c\u8fd8\u53ef\u4ee5\u5e94\u7528\u5728\u5404\u79cd\u573a\u5408\uff0c\u6bd4\u5982\u6559\u80b2\u8f6f\u4ef6\u3001\u6e38\u620f\u5f00\u53d1\u7b49\u3002<\/p>\n<\/p>\n<p><h4>5.1 \u6559\u80b2\u8f6f\u4ef6<\/h4>\n<\/p>\n<p><p>\u5728\u6559\u80b2\u8f6f\u4ef6\u4e2d\uff0c\u4e5d\u4e5d\u4e58\u6cd5\u8868\u662f\u4e00\u4e2a\u57fa\u672c\u7684\u6570\u5b66\u6559\u5b66\u5de5\u5177\u3002\u901a\u8fc7\u56fe\u5f62\u5316\u754c\u9762\u548c\u4ea4\u4e92\u529f\u80fd\uff0c\u53ef\u4ee5\u5e2e\u52a9\u5b66\u751f\u66f4\u597d\u5730\u7406\u89e3\u548c\u8bb0\u5fc6\u4e58\u6cd5\u8868\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">class MultiplicationTableApp(tk.Tk):<\/p>\n<p>    def __init__(self):<\/p>\n<p>        super().__init__()<\/p>\n<p>        self.title(&quot;\u4e5d\u4e5d\u4e58\u6cd5\u8868\u6559\u80b2\u8f6f\u4ef6&quot;)<\/p>\n<p>        self.geometry(&quot;400x400&quot;)<\/p>\n<p>        self.create_widgets()<\/p>\n<p>    def create_widgets(self):<\/p>\n<p>        label = tk.Label(self, text=&quot;\u4e5d\u4e5d\u4e58\u6cd5\u8868&quot;, font=(&quot;Arial&quot;, 16))<\/p>\n<p>        label.pack()<\/p>\n<p>        table_text = display_multiplication_table()<\/p>\n<p>        table_label = tk.Label(self, text=table_text, font=(&quot;Arial&quot;, 12))<\/p>\n<p>        table_label.pack()<\/p>\n<p>if __name__ == &quot;__main__&quot;:<\/p>\n<p>    app = MultiplicationTableApp()<\/p>\n<p>    app.mainloop()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>5.2 \u6e38\u620f\u5f00\u53d1<\/h4>\n<\/p>\n<p><p>\u5728\u6e38\u620f\u5f00\u53d1\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4e5d\u4e5d\u4e58\u6cd5\u8868\u6765\u8bbe\u8ba1\u4e00\u4e9b\u6570\u5b66\u95ef\u5173\u6e38\u620f\u3002\u4f8b\u5982\uff0c\u73a9\u5bb6\u9700\u8981\u56de\u7b54\u4e58\u6cd5\u95ee\u9898\u624d\u80fd\u901a\u8fc7\u5173\u5361\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import random<\/p>\n<p>class MultiplicationGame(tk.Tk):<\/p>\n<p>    def __init__(self):<\/p>\n<p>        super().__init__()<\/p>\n<p>        self.title(&quot;\u4e5d\u4e5d\u4e58\u6cd5\u6e38\u620f&quot;)<\/p>\n<p>        self.geometry(&quot;400x400&quot;)<\/p>\n<p>        self.create_widgets()<\/p>\n<p>        self.generate_question()<\/p>\n<p>    def create_widgets(self):<\/p>\n<p>        self.question_label = tk.Label(self, text=&quot;&quot;, font=(&quot;Arial&quot;, 16))<\/p>\n<p>        self.question_label.pack()<\/p>\n<p>        self.answer_entry = tk.Entry(self, font=(&quot;Arial&quot;, 16))<\/p>\n<p>        self.answer_entry.pack()<\/p>\n<p>        self.submit_button = tk.Button(self, text=&quot;\u63d0\u4ea4&quot;, command=self.check_answer)<\/p>\n<p>        self.submit_button.pack()<\/p>\n<p>    def generate_question(self):<\/p>\n<p>        self.a = random.randint(1, 9)<\/p>\n<p>        self.b = random.randint(1, 9)<\/p>\n<p>        self.question_label.config(text=f&quot;{self.a} * {self.b} = ?&quot;)<\/p>\n<p>    def check_answer(self):<\/p>\n<p>        answer = int(self.answer_entry.get())<\/p>\n<p>        if answer == self.a * self.b:<\/p>\n<p>            self.question_label.config(text=&quot;\u6b63\u786e\uff01&quot;)<\/p>\n<p>        else:<\/p>\n<p>            self.question_label.config(text=&quot;\u9519\u8bef\uff0c\u518d\u8bd5\u4e00\u6b21&quot;)<\/p>\n<p>        self.generate_question()<\/p>\n<p>        self.answer_entry.delete(0, tk.END)<\/p>\n<p>if __name__ == &quot;__main__&quot;:<\/p>\n<p>    game = MultiplicationGame()<\/p>\n<p>    game.mainloop()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u516d\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u51e0\u4e2a\u65b9\u9762\u7684\u4ecb\u7ecd\uff0c\u6211\u4eec\u53ef\u4ee5\u5168\u9762\u4e86\u89e3\u5982\u4f55\u7528Python\u5236\u4f5c\u4e5d\u4e5d\u4e58\u6cd5\u8868\u3002<strong>\u901a\u8fc7\u5d4c\u5957\u5faa\u73af\u3001\u4f7f\u7528\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u3001\u5229\u7528print\u51fd\u6570\u3001\u5c01\u88c5\u6210\u51fd\u6570\u3001\u56fe\u5f62\u5316\u754c\u9762\u663e\u793a<\/strong>\uff0c\u6211\u4eec\u53ef\u4ee5\u7075\u6d3b\u5730\u751f\u6210\u5e76\u5c55\u793a\u4e5d\u4e5d\u4e58\u6cd5\u8868\u3002\u65e0\u8bba\u662f\u57fa\u7840\u7684\u6570\u5b66\u7ec3\u4e60\uff0c\u8fd8\u662f\u5728\u6559\u80b2\u8f6f\u4ef6\u548c\u6e38\u620f\u5f00\u53d1\u4e2d\u7684\u5e94\u7528\uff0c\u4e5d\u4e5d\u4e58\u6cd5\u8868\u90fd\u662f\u4e00\u4e2a\u975e\u5e38\u5b9e\u7528\u7684\u5de5\u5177\u3002\u638c\u63e1\u8fd9\u4e9b\u6280\u5de7\uff0c\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u5728\u65e5\u5e38\u7f16\u7a0b\u4e2d\u66f4\u52a0\u5f97\u5fc3\u5e94\u624b\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u7528Python\u7f16\u5199\u4e00\u4e2a\u7b80\u5355\u7684\u4e5d\u4e5d\u4e58\u6cd5\u8868\u7a0b\u5e8f\uff1f<\/strong><br \/>\u8981\u521b\u5efa\u4e00\u4e2a\u4e5d\u4e5d\u4e58\u6cd5\u8868\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u5d4c\u5957\u7684for\u5faa\u73af\u3002\u5916\u5c42\u5faa\u73af\u7528\u4e8e\u904d\u5386\u4e58\u6570\uff0c\u5185\u5c42\u5faa\u73af\u5219\u7528\u4e8e\u904d\u5386\u88ab\u4e58\u6570\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u4ee3\u7801\u793a\u4f8b\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} * {i} = {i * j}&quot;, end=&quot;\\t&quot;)\n    print()\n<\/code><\/pre>\n<p>\u8fd0\u884c\u8fd9\u6bb5\u4ee3\u7801\u4f1a\u751f\u6210\u6807\u51c6\u7684\u4e5d\u4e5d\u4e58\u6cd5\u8868\u3002<\/p>\n<p><strong>\u4f7f\u7528Python\u5236\u4f5c\u4e5d\u4e5d\u4e58\u6cd5\u8868\u65f6\uff0c\u5982\u4f55\u683c\u5f0f\u5316\u8f93\u51fa\u4ee5\u63d0\u9ad8\u53ef\u8bfb\u6027\uff1f<\/strong><br \/>\u4e3a\u4e86\u63d0\u9ad8\u4e58\u6cd5\u8868\u7684\u53ef\u8bfb\u6027\uff0c\u53ef\u4ee5\u8c03\u6574\u8f93\u51fa\u683c\u5f0f\u3002\u4f8b\u5982\uff0c\u901a\u8fc7\u4f7f\u7528\u5236\u8868\u7b26\uff08\\t\uff09\u6216\u7a7a\u683c\uff0c\u4f7f\u6bcf\u4e00\u5217\u5bf9\u9f50\u3002\u53ef\u4ee5\u8003\u8651\u4f7f\u7528\u5b57\u7b26\u4e32\u683c\u5f0f\u5316\u65b9\u6cd5\uff0c\u4f8b\u5982<code>str.format()<\/code>\u6216f-string\uff0c\u4ee5\u4fbf\u5728\u8f93\u51fa\u65f6\u4fdd\u6301\u5217\u7684\u6574\u9f50\u3002\u4f8b\u5982\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} * {i} = {i * j:2}&quot;, end=&quot;  &quot;)\n    print()\n<\/code><\/pre>\n<p>\u5728\u8fd9\u91cc\uff0c<code>:2<\/code>\u786e\u4fdd\u6bcf\u4e2a\u4e58\u79ef\u81f3\u5c11\u5360\u7528\u4e24\u4e2a\u5b57\u7b26\u7684\u7a7a\u95f4\uff0c\u4ece\u800c\u4fdd\u6301\u6574\u9f50\u7684\u5217\u3002<\/p>\n<p><strong>\u662f\u5426\u53ef\u4ee5\u4f7f\u7528\u5176\u4ed6Python\u5e93\u6765\u751f\u6210\u4e5d\u4e5d\u4e58\u6cd5\u8868\uff1f<\/strong><br \/>\u5f53\u7136\uff0c\u53ef\u4ee5\u4f7f\u7528\u50cfPandas\u8fd9\u6837\u7684\u5e93\u6765\u521b\u5efa\u4e5d\u4e5d\u4e58\u6cd5\u8868\u3002Pandas\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u6570\u636e\u5904\u7406\u529f\u80fd\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u5c06\u7ed3\u679c\u5b58\u50a8\u5728DataFrame\u4e2d\uff0c\u5e76\u8fdb\u884c\u683c\u5f0f\u5316\u8f93\u51fa\u3002\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-python\">import pandas as pd\n\ndata = [[i * j for j in range(1, 10)] for i in range(1, 10)]\ndf = pd.DataFrame(data, index=range(1, 10), columns=range(1, 10))\nprint(df)\n<\/code><\/pre>\n<p>\u8fd9\u79cd\u65b9\u5f0f\u4e0d\u4ec5\u751f\u6210\u4e5d\u4e5d\u4e58\u6cd5\u8868\uff0c\u8fd8\u80fd\u591f\u5229\u7528Pandas\u7684\u529f\u80fd\u8fdb\u884c\u8fdb\u4e00\u6b65\u7684\u6570\u636e\u5206\u6790\u548c\u5904\u7406\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5982\u4f55\u7528Python\u505a\u51fa\u4e5d\u4e5d\u4e58\u6cd5\u8868 \u7528Python\u5236\u4f5c\u4e5d\u4e5d\u4e58\u6cd5\u8868\u975e\u5e38\u7b80\u5355\uff0c\u53ea\u9700\u5229\u7528\u5faa\u73af\u7ed3\u6784\u548c\u5b57\u7b26\u4e32\u683c\u5f0f\u5316\u5373\u53ef\u5b9e\u73b0 [&hellip;]","protected":false},"author":3,"featured_media":1129241,"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\/1129231"}],"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=1129231"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1129231\/revisions"}],"predecessor-version":[{"id":1129244,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1129231\/revisions\/1129244"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1129241"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1129231"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1129231"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1129231"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}