{"id":1075530,"date":"2025-01-08T11:45:08","date_gmt":"2025-01-08T03:45:08","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1075530.html"},"modified":"2025-01-08T11:45:12","modified_gmt":"2025-01-08T03:45:12","slug":"python%e5%a6%82%e4%bd%95%e8%be%93%e5%85%a5%e4%b8%80%e7%82%b9%e7%9a%84%e5%9d%90%e6%a0%87-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1075530.html","title":{"rendered":"python\u5982\u4f55\u8f93\u5165\u4e00\u70b9\u7684\u5750\u6807"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24180535\/142d5558-a345-4c97-be3f-7135551d6e54.webp\" alt=\"python\u5982\u4f55\u8f93\u5165\u4e00\u70b9\u7684\u5750\u6807\" \/><\/p>\n<p><p> <strong>Python\u4e2d\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u8f93\u5165\u70b9\u7684\u5750\u6807\uff0c\u4f8b\u5982\uff1a\u624b\u52a8\u8f93\u5165\u3001\u901a\u8fc7\u51fd\u6570\u4f20\u53c2\u3001\u4ece\u6587\u4ef6\u8bfb\u53d6\u7b49\u3002\u6700\u5e38\u7528\u7684\u65b9\u5f0f\u5305\u62ec\uff1a\u4f7f\u7528input()\u51fd\u6570\u3001\u5b9a\u4e49\u51fd\u6570\u53c2\u6570\u3001\u8bfb\u53d6CSV\u6587\u4ef6\u3002\u4ee5\u4e0b\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u4f7f\u7528input()\u51fd\u6570\u624b\u52a8\u8f93\u5165\u70b9\u7684\u5750\u6807\uff0c\u5e76\u901a\u8fc7\u793a\u4f8b\u5c55\u793a\u5982\u4f55\u4f7f\u7528\u8fd9\u4e9b\u65b9\u6cd5\u3002<\/strong><\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528input()\u51fd\u6570\u624b\u52a8\u8f93\u5165\u5750\u6807<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528Python\u5185\u7f6e\u7684<code>input()<\/code>\u51fd\u6570\u53ef\u4ee5\u65b9\u4fbf\u5730\u4ece\u7528\u6237\u5904\u83b7\u53d6\u8f93\u5165\u3002\u4ee5\u4e0b\u793a\u4f8b\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528<code>input()<\/code>\u51fd\u6570\u83b7\u53d6\u4e00\u4e2a\u70b9\u7684\u5750\u6807\uff0c\u5e76\u5c06\u5176\u5b58\u50a8\u5728\u53d8\u91cf\u4e2d\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u83b7\u53d6\u7528\u6237\u8f93\u5165\u7684\u70b9\u5750\u6807<\/p>\n<p>x = float(input(&quot;\u8bf7\u8f93\u5165x\u5750\u6807: &quot;))<\/p>\n<p>y = float(input(&quot;\u8bf7\u8f93\u5165y\u5750\u6807: &quot;))<\/p>\n<h2><strong>\u6253\u5370\u8f93\u5165\u7684\u5750\u6807<\/strong><\/h2>\n<p>print(f&quot;\u8f93\u5165\u7684\u70b9\u5750\u6807\u4e3a: ({x}, {y})&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>input()<\/code>\u51fd\u6570\u5206\u522b\u83b7\u53d6\u7528\u6237\u8f93\u5165\u7684x\u548cy\u5750\u6807\uff0c\u5e76\u5c06\u5176\u8f6c\u6362\u4e3a\u6d6e\u70b9\u6570\u5b58\u50a8\u5728\u53d8\u91cf<code>x<\/code>\u548c<code>y<\/code>\u4e2d\u3002\u7136\u540e\uff0c\u6211\u4eec\u4f7f\u7528<code>print()<\/code>\u51fd\u6570\u6253\u5370\u51fa\u8f93\u5165\u7684\u70b9\u5750\u6807\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u5b9a\u4e49\u51fd\u6570\u53c2\u6570\u4f20\u9012\u5750\u6807<\/h3>\n<\/p>\n<p><p>\u53e6\u4e00\u79cd\u65b9\u5f0f\u662f\u5b9a\u4e49\u51fd\u6570\u5e76\u901a\u8fc7\u53c2\u6570\u4f20\u9012\u5750\u6807\u3002\u8fd9\u79cd\u65b9\u5f0f\u9002\u7528\u4e8e\u9700\u8981\u5728\u7a0b\u5e8f\u4e2d\u591a\u6b21\u4f7f\u7528\u7684\u60c5\u51b5\u3002\u4ee5\u4e0b\u793a\u4f8b\u5c55\u793a\u4e86\u5982\u4f55\u5b9a\u4e49\u4e00\u4e2a\u51fd\u6570\u5e76\u901a\u8fc7\u53c2\u6570\u4f20\u9012\u70b9\u7684\u5750\u6807\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def print_coordinates(x, y):<\/p>\n<p>    &quot;&quot;&quot;<\/p>\n<p>    \u6253\u5370\u70b9\u7684\u5750\u6807<\/p>\n<p>    :param x: x\u5750\u6807<\/p>\n<p>    :param y: y\u5750\u6807<\/p>\n<p>    &quot;&quot;&quot;<\/p>\n<p>    print(f&quot;\u70b9\u7684\u5750\u6807\u4e3a: ({x}, {y})&quot;)<\/p>\n<h2><strong>\u8c03\u7528\u51fd\u6570\u5e76\u4f20\u9012\u5750\u6807\u53c2\u6570<\/strong><\/h2>\n<p>print_coordinates(3.5, 7.2)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a\u540d\u4e3a<code>print_coordinates<\/code>\u7684\u51fd\u6570\uff0c\u8be5\u51fd\u6570\u63a5\u53d7\u4e24\u4e2a\u53c2\u6570x\u548cy\uff0c\u8868\u793a\u70b9\u7684\u5750\u6807\u3002\u5728\u51fd\u6570\u5185\u90e8\uff0c\u6211\u4eec\u4f7f\u7528<code>print()<\/code>\u51fd\u6570\u6253\u5370\u51fa\u70b9\u7684\u5750\u6807\u3002\u6700\u540e\uff0c\u6211\u4eec\u8c03\u7528<code>print_coordinates<\/code>\u51fd\u6570\u5e76\u4f20\u9012\u5177\u4f53\u7684\u5750\u6807\u53c2\u6570\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u4ece\u6587\u4ef6\u8bfb\u53d6\u5750\u6807<\/h3>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u70b9\u7684\u5750\u6807\u53ef\u80fd\u5b58\u50a8\u5728\u6587\u4ef6\u4e2d\uff0c\u4f8b\u5982CSV\u6587\u4ef6\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Python\u7684<code>csv<\/code>\u6a21\u5757\u8bfb\u53d6\u6587\u4ef6\u4e2d\u7684\u5750\u6807\u3002\u4ee5\u4e0b\u793a\u4f8b\u5c55\u793a\u4e86\u5982\u4f55\u4eceCSV\u6587\u4ef6\u4e2d\u8bfb\u53d6\u70b9\u7684\u5750\u6807\uff1a<\/p>\n<\/p>\n<p><p>\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u540d\u4e3a<code>points.csv<\/code>\u7684\u6587\u4ef6\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code>x,y<\/p>\n<p>1.2,3.4<\/p>\n<p>5.6,7.8<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u8bfb\u53d6\u6587\u4ef6\u4e2d\u7684\u5750\u6807\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import csv<\/p>\n<h2><strong>\u6253\u5f00CSV\u6587\u4ef6<\/strong><\/h2>\n<p>with open(&#39;points.csv&#39;, mode=&#39;r&#39;) as file:<\/p>\n<p>    # \u521b\u5efaCSV\u8bfb\u53d6\u5668<\/p>\n<p>    csv_reader = csv.reader(file)<\/p>\n<p>    # \u8df3\u8fc7\u8868\u5934<\/p>\n<p>    next(csv_reader)<\/p>\n<p>    # \u9010\u884c\u8bfb\u53d6CSV\u6587\u4ef6\u4e2d\u7684\u5750\u6807<\/p>\n<p>    for row in csv_reader:<\/p>\n<p>        x, y = float(row[0]), float(row[1])<\/p>\n<p>        print(f&quot;\u8bfb\u53d6\u7684\u70b9\u5750\u6807\u4e3a: ({x}, {y})&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>csv<\/code>\u6a21\u5757\u6253\u5f00\u540d\u4e3a<code>points.csv<\/code>\u7684\u6587\u4ef6\uff0c\u5e76\u521b\u5efa\u4e00\u4e2aCSV\u8bfb\u53d6\u5668<code>csv_reader<\/code>\u3002\u7136\u540e\uff0c\u6211\u4eec\u4f7f\u7528<code>next()<\/code>\u51fd\u6570\u8df3\u8fc7\u8868\u5934\u884c\uff0c\u5e76\u9010\u884c\u8bfb\u53d6\u6587\u4ef6\u4e2d\u7684\u5750\u6807\u3002\u5bf9\u4e8e\u6bcf\u4e00\u884c\uff0c\u6211\u4eec\u5c06\u5750\u6807\u8f6c\u6362\u4e3a\u6d6e\u70b9\u6570\u5e76\u6253\u5370\u51fa\u6765\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u4f7f\u7528\u56fe\u5f62\u754c\u9762\u8f93\u5165\u5750\u6807<\/h3>\n<\/p>\n<p><p>\u9664\u4e86\u547d\u4ee4\u884c\u8f93\u5165\u5916\uff0c\u6211\u4eec\u8fd8\u53ef\u4ee5\u4f7f\u7528\u56fe\u5f62\u754c\u9762\uff08GUI\uff09\u6765\u8f93\u5165\u70b9\u7684\u5750\u6807\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528Python\u7684<code>tkinter<\/code>\u5e93\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684\u56fe\u5f62\u754c\u9762\uff0c\u8ba9\u7528\u6237\u8f93\u5165\u5750\u6807\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import tkinter as tk<\/p>\n<p>from tkinter import messagebox<\/p>\n<p>def submit():<\/p>\n<p>    x = float(entry_x.get())<\/p>\n<p>    y = float(entry_y.get())<\/p>\n<p>    messagebox.showinfo(&quot;\u5750\u6807&quot;, f&quot;\u8f93\u5165\u7684\u70b9\u5750\u6807\u4e3a: ({x}, {y})&quot;)<\/p>\n<h2><strong>\u521b\u5efa\u4e3b\u7a97\u53e3<\/strong><\/h2>\n<p>root = tk.Tk()<\/p>\n<p>root.title(&quot;\u8f93\u5165\u70b9\u5750\u6807&quot;)<\/p>\n<h2><strong>\u521b\u5efa\u5e76\u653e\u7f6e\u6807\u7b7e\u548c\u8f93\u5165\u6846<\/strong><\/h2>\n<p>tk.Label(root, text=&quot;\u8bf7\u8f93\u5165x\u5750\u6807:&quot;).grid(row=0, column=0)<\/p>\n<p>entry_x = tk.Entry(root)<\/p>\n<p>entry_x.grid(row=0, column=1)<\/p>\n<p>tk.Label(root, text=&quot;\u8bf7\u8f93\u5165y\u5750\u6807:&quot;).grid(row=1, column=0)<\/p>\n<p>entry_y = tk.Entry(root)<\/p>\n<p>entry_y.grid(row=1, column=1)<\/p>\n<h2><strong>\u521b\u5efa\u5e76\u653e\u7f6e\u63d0\u4ea4\u6309\u94ae<\/strong><\/h2>\n<p>tk.Button(root, text=&quot;\u63d0\u4ea4&quot;, command=submit).grid(row=2, columnspan=2)<\/p>\n<h2><strong>\u8fd0\u884c\u4e3b\u5faa\u73af<\/strong><\/h2>\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><p>\u5728\u4e0a\u8ff0\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>tkinter<\/code>\u5e93\u521b\u5efa\u4e86\u4e00\u4e2a\u7b80\u5355\u7684\u56fe\u5f62\u754c\u9762\uff0c\u5305\u62ec\u6807\u7b7e\u3001\u8f93\u5165\u6846\u548c\u6309\u94ae\u3002\u5f53\u7528\u6237\u70b9\u51fb\u201c\u63d0\u4ea4\u201d\u6309\u94ae\u65f6\uff0c\u4f1a\u8c03\u7528<code>submit<\/code>\u51fd\u6570\uff0c\u83b7\u53d6\u8f93\u5165\u7684\u5750\u6807\u5e76\u663e\u793a\u5728\u6d88\u606f\u6846\u4e2d\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u4f7f\u7528\u6570\u636e\u7ed3\u6784\u5b58\u50a8\u5750\u6807<\/h3>\n<\/p>\n<p><p>\u5728\u7a0b\u5e8f\u4e2d\u5904\u7406\u70b9\u7684\u5750\u6807\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u6570\u636e\u7ed3\u6784\uff08\u5982\u5217\u8868\u3001\u5143\u7ec4\u3001\u5b57\u5178\uff09\u6765\u5b58\u50a8\u548c\u7ba1\u7406\u5750\u6807\u3002\u4ee5\u4e0b\u793a\u4f8b\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528\u8fd9\u4e9b\u6570\u636e\u7ed3\u6784\u5b58\u50a8\u70b9\u7684\u5750\u6807\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u4f7f\u7528\u5143\u7ec4\u5b58\u50a8\u5750\u6807<\/p>\n<p>point = (1.2, 3.4)<\/p>\n<p>print(f&quot;\u70b9\u7684\u5750\u6807\u4e3a: {point}&quot;)<\/p>\n<h2><strong>\u4f7f\u7528\u5217\u8868\u5b58\u50a8\u5750\u6807<\/strong><\/h2>\n<p>points_list = [(1.2, 3.4), (5.6, 7.8)]<\/p>\n<p>print(&quot;\u70b9\u7684\u5750\u6807\u5217\u8868:&quot;)<\/p>\n<p>for p in points_list:<\/p>\n<p>    print(p)<\/p>\n<h2><strong>\u4f7f\u7528\u5b57\u5178\u5b58\u50a8\u5750\u6807<\/strong><\/h2>\n<p>points_dict = {&#39;point1&#39;: (1.2, 3.4), &#39;point2&#39;: (5.6, 7.8)}<\/p>\n<p>print(&quot;\u70b9\u7684\u5750\u6807\u5b57\u5178:&quot;)<\/p>\n<p>for key, value in points_dict.items():<\/p>\n<p>    print(f&quot;{key}: {value}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528\u5143\u7ec4\u3001\u5217\u8868\u548c\u5b57\u5178\u5b58\u50a8\u70b9\u7684\u5750\u6807\uff0c\u5e76\u5206\u522b\u6253\u5370\u51fa\u6765\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u4f7f\u7528\u7c7b\u548c\u5bf9\u8c61\u7ba1\u7406\u5750\u6807<\/h3>\n<\/p>\n<p><p>\u5728\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\u4e2d\uff0c\u53ef\u4ee5\u5b9a\u4e49\u7c7b\u6765\u7ba1\u7406\u70b9\u7684\u5750\u6807\u3002\u4ee5\u4e0b\u793a\u4f8b\u5c55\u793a\u4e86\u5982\u4f55\u5b9a\u4e49\u4e00\u4e2a\u7c7b\u5e76\u4f7f\u7528\u5bf9\u8c61\u5b58\u50a8\u548c\u7ba1\u7406\u5750\u6807\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">class Point:<\/p>\n<p>    def __init__(self, x, y):<\/p>\n<p>        self.x = x<\/p>\n<p>        self.y = y<\/p>\n<p>    def display(self):<\/p>\n<p>        print(f&quot;\u70b9\u7684\u5750\u6807\u4e3a: ({self.x}, {self.y})&quot;)<\/p>\n<h2><strong>\u521b\u5efaPoint\u5bf9\u8c61\u5e76\u8c03\u7528\u65b9\u6cd5<\/strong><\/h2>\n<p>point = Point(1.2, 3.4)<\/p>\n<p>point.display()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a\u540d\u4e3a<code>Point<\/code>\u7684\u7c7b\uff0c\u8be5\u7c7b\u5305\u542b\u4e00\u4e2a\u6784\u9020\u51fd\u6570<code>__init__<\/code>\u548c\u4e00\u4e2a\u65b9\u6cd5<code>display<\/code>\u3002\u6784\u9020\u51fd\u6570\u63a5\u53d7\u4e24\u4e2a\u53c2\u6570x\u548cy\uff0c\u5e76\u5c06\u5176\u8d4b\u503c\u7ed9\u5b9e\u4f8b\u53d8\u91cf\u3002<code>display<\/code>\u65b9\u6cd5\u7528\u4e8e\u6253\u5370\u70b9\u7684\u5750\u6807\u3002\u7136\u540e\uff0c\u6211\u4eec\u521b\u5efa\u4e00\u4e2a<code>Point<\/code>\u5bf9\u8c61\u5e76\u8c03\u7528<code>display<\/code>\u65b9\u6cd5\u663e\u793a\u5750\u6807\u3002<\/p>\n<\/p>\n<p><h3>\u4e03\u3001\u4ece\u6570\u636e\u5e93\u8bfb\u53d6\u5750\u6807<\/h3>\n<\/p>\n<p><p>\u5982\u679c\u70b9\u7684\u5750\u6807\u5b58\u50a8\u5728\u6570\u636e\u5e93\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528Python\u7684\u6570\u636e\u5e93\u8fde\u63a5\u5e93\uff08\u5982<code>sqlite3<\/code>\uff09\u8bfb\u53d6\u5750\u6807\u3002\u4ee5\u4e0b\u793a\u4f8b\u5c55\u793a\u4e86\u5982\u4f55\u4eceSQLite\u6570\u636e\u5e93\u4e2d\u8bfb\u53d6\u70b9\u7684\u5750\u6807\uff1a<\/p>\n<\/p>\n<p><p>\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2aSQLite\u6570\u636e\u5e93\u6587\u4ef6<code>points.db<\/code>\uff0c\u5176\u4e2d\u5305\u542b\u4e00\u4e2a\u8868<code>points<\/code>\uff0c\u7ed3\u6784\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-sql\">CREATE TABLE points (<\/p>\n<p>    id INTEGER PRIMARY KEY,<\/p>\n<p>    x REAL,<\/p>\n<p>    y REAL<\/p>\n<p>);<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u4ece\u6570\u636e\u5e93\u4e2d\u8bfb\u53d6\u5750\u6807\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import sqlite3<\/p>\n<h2><strong>\u8fde\u63a5\u5230SQLite\u6570\u636e\u5e93<\/strong><\/h2>\n<p>conn = sqlite3.connect(&#39;points.db&#39;)<\/p>\n<p>cursor = conn.cursor()<\/p>\n<h2><strong>\u6267\u884c\u67e5\u8be2\u5e76\u83b7\u53d6\u7ed3\u679c<\/strong><\/h2>\n<p>cursor.execute(&quot;SELECT x, y FROM points&quot;)<\/p>\n<p>rows = cursor.fetchall()<\/p>\n<h2><strong>\u6253\u5370\u8bfb\u53d6\u7684\u5750\u6807<\/strong><\/h2>\n<p>for row in rows:<\/p>\n<p>    x, y = row<\/p>\n<p>    print(f&quot;\u8bfb\u53d6\u7684\u70b9\u5750\u6807\u4e3a: ({x}, {y})&quot;)<\/p>\n<h2><strong>\u5173\u95ed\u6570\u636e\u5e93\u8fde\u63a5<\/strong><\/h2>\n<p>conn.close()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>sqlite3<\/code>\u6a21\u5757\u8fde\u63a5\u5230\u540d\u4e3a<code>points.db<\/code>\u7684SQLite\u6570\u636e\u5e93\uff0c\u5e76\u521b\u5efa\u4e00\u4e2a\u6e38\u6807<code>cursor<\/code>\u3002\u7136\u540e\uff0c\u6211\u4eec\u6267\u884c\u67e5\u8be2\u8bed\u53e5<code>SELECT x, y FROM points<\/code>\u83b7\u53d6\u70b9\u7684\u5750\u6807\uff0c\u5e76\u4f7f\u7528<code>fetchall()<\/code>\u65b9\u6cd5\u83b7\u53d6\u6240\u6709\u7ed3\u679c\u3002\u6700\u540e\uff0c\u6211\u4eec\u904d\u5386\u7ed3\u679c\u5e76\u6253\u5370\u51fa\u6bcf\u4e2a\u70b9\u7684\u5750\u6807\u3002<\/p>\n<\/p>\n<p><h3>\u516b\u3001\u4f7f\u7528\u914d\u7f6e\u6587\u4ef6\u8bfb\u53d6\u5750\u6807<\/h3>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u70b9\u7684\u5750\u6807\u53ef\u80fd\u5b58\u50a8\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\uff08\u5982INI\u6587\u4ef6\uff09\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Python\u7684<code>configparser<\/code>\u6a21\u5757\u8bfb\u53d6\u914d\u7f6e\u6587\u4ef6\u4e2d\u7684\u5750\u6807\u3002\u4ee5\u4e0b\u793a\u4f8b\u5c55\u793a\u4e86\u5982\u4f55\u4eceINI\u6587\u4ef6\u4e2d\u8bfb\u53d6\u70b9\u7684\u5750\u6807\uff1a<\/p>\n<\/p>\n<p><p>\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u540d\u4e3a<code>points.ini<\/code>\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-ini\">[Point1]<\/p>\n<p>x = 1.2<\/p>\n<p>y = 3.4<\/p>\n<p>[Point2]<\/p>\n<p>x = 5.6<\/p>\n<p>y = 7.8<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u8bfb\u53d6\u914d\u7f6e\u6587\u4ef6\u4e2d\u7684\u5750\u6807\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import configparser<\/p>\n<h2><strong>\u521b\u5efa\u914d\u7f6e\u89e3\u6790\u5668<\/strong><\/h2>\n<p>config = configparser.ConfigParser()<\/p>\n<h2><strong>\u8bfb\u53d6\u914d\u7f6e\u6587\u4ef6<\/strong><\/h2>\n<p>config.read(&#39;points.ini&#39;)<\/p>\n<h2><strong>\u83b7\u53d6\u5e76\u6253\u5370\u914d\u7f6e\u6587\u4ef6\u4e2d\u7684\u5750\u6807<\/strong><\/h2>\n<p>for section in config.sections():<\/p>\n<p>    x = config.getfloat(section, &#39;x&#39;)<\/p>\n<p>    y = config.getfloat(section, &#39;y&#39;)<\/p>\n<p>    print(f&quot;{section}\u7684\u70b9\u5750\u6807\u4e3a: ({x}, {y})&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>configparser<\/code>\u6a21\u5757\u521b\u5efa\u4e86\u4e00\u4e2a\u914d\u7f6e\u89e3\u6790\u5668<code>config<\/code>\uff0c\u5e76\u8bfb\u53d6\u540d\u4e3a<code>points.ini<\/code>\u7684\u914d\u7f6e\u6587\u4ef6\u3002\u7136\u540e\uff0c\u6211\u4eec\u904d\u5386\u914d\u7f6e\u6587\u4ef6\u7684\u6240\u6709\u8282\uff0c\u5e76\u83b7\u53d6\u6bcf\u4e2a\u8282\u4e2d\u7684x\u548cy\u5750\u6807\uff0c\u5e76\u6253\u5370\u51fa\u6765\u3002<\/p>\n<\/p>\n<p><h3>\u4e5d\u3001\u4f7f\u7528\u7f51\u7edc\u8bf7\u6c42\u83b7\u53d6\u5750\u6807<\/h3>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u5e94\u7528\u4e2d\uff0c\u70b9\u7684\u5750\u6807\u53ef\u80fd\u901a\u8fc7\u7f51\u7edc\u8bf7\u6c42\u83b7\u53d6\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528<code>requests<\/code>\u5e93\u53d1\u9001HTTP\u8bf7\u6c42\u83b7\u53d6\u5750\u6807\u6570\u636e\u3002\u4ee5\u4e0b\u793a\u4f8b\u5c55\u793a\u4e86\u5982\u4f55\u901a\u8fc7\u7f51\u7edc\u8bf7\u6c42\u83b7\u53d6\u70b9\u7684\u5750\u6807\uff1a<\/p>\n<\/p>\n<p><p>\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2aAPI\u7aef\u70b9\u8fd4\u56de\u70b9\u7684\u5750\u6807\uff0c\u54cd\u5e94\u6570\u636e\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-json\">[<\/p>\n<p>    {&quot;x&quot;: 1.2, &quot;y&quot;: 3.4},<\/p>\n<p>    {&quot;x&quot;: 5.6, &quot;y&quot;: 7.8}<\/p>\n<p>]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u53d1\u9001\u7f51\u7edc\u8bf7\u6c42\u83b7\u53d6\u5750\u6807\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import requests<\/p>\n<h2><strong>\u53d1\u9001GET\u8bf7\u6c42\u83b7\u53d6\u5750\u6807\u6570\u636e<\/strong><\/h2>\n<p>response = requests.get(&#39;https:\/\/api.example.com\/points&#39;)<\/p>\n<p>points = response.json()<\/p>\n<h2><strong>\u6253\u5370\u83b7\u53d6\u7684\u5750\u6807<\/strong><\/h2>\n<p>for point in points:<\/p>\n<p>    x, y = point[&#39;x&#39;], point[&#39;y&#39;]<\/p>\n<p>    print(f&quot;\u83b7\u53d6\u7684\u70b9\u5750\u6807\u4e3a: ({x}, {y})&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>requests<\/code>\u5e93\u53d1\u9001GET\u8bf7\u6c42\u5230API\u7aef\u70b9<code>https:\/\/api.example.com\/points<\/code>\uff0c\u5e76\u5c06\u54cd\u5e94\u6570\u636e\u89e3\u6790\u4e3aJSON\u683c\u5f0f\u3002\u7136\u540e\uff0c\u6211\u4eec\u904d\u5386JSON\u6570\u636e\u5e76\u6253\u5370\u6bcf\u4e2a\u70b9\u7684\u5750\u6807\u3002<\/p>\n<\/p>\n<p><h3>\u5341\u3001\u4f7f\u7528\u73af\u5883\u53d8\u91cf\u83b7\u53d6\u5750\u6807<\/h3>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u53ef\u4ee5\u4f7f\u7528\u73af\u5883\u53d8\u91cf\u5b58\u50a8\u70b9\u7684\u5750\u6807\uff0c\u5e76\u5728\u7a0b\u5e8f\u4e2d\u8bfb\u53d6\u8fd9\u4e9b\u73af\u5883\u53d8\u91cf\u3002\u4ee5\u4e0b\u793a\u4f8b\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528\u73af\u5883\u53d8\u91cf\u5b58\u50a8\u548c\u83b7\u53d6\u70b9\u7684\u5750\u6807\uff1a<\/p>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">export POINT_X=1.2<\/p>\n<p>export POINT_Y=3.4<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\uff0c\u5728Python\u7a0b\u5e8f\u4e2d\u8bfb\u53d6\u73af\u5883\u53d8\u91cf\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import os<\/p>\n<h2><strong>\u83b7\u53d6\u73af\u5883\u53d8\u91cf\u4e2d\u7684\u5750\u6807<\/strong><\/h2>\n<p>x = float(os.getenv(&#39;POINT_X&#39;))<\/p>\n<p>y = float(os.getenv(&#39;POINT_Y&#39;))<\/p>\n<h2><strong>\u6253\u5370\u83b7\u53d6\u7684\u5750\u6807<\/strong><\/h2>\n<p>print(f&quot;\u73af\u5883\u53d8\u91cf\u4e2d\u7684\u70b9\u5750\u6807\u4e3a: ({x}, {y})&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>os<\/code>\u6a21\u5757\u7684<code>getenv()<\/code>\u51fd\u6570\u8bfb\u53d6\u73af\u5883\u53d8\u91cf<code>POINT_X<\/code>\u548c<code>POINT_Y<\/code>\uff0c\u5e76\u5c06\u5176\u8f6c\u6362\u4e3a\u6d6e\u70b9\u6570\u3002\u7136\u540e\uff0c\u6211\u4eec\u6253\u5370\u83b7\u53d6\u7684\u5750\u6807\u3002<\/p>\n<\/p>\n<p><h3>\u5341\u4e00\u3001\u4f7f\u7528\u547d\u4ee4\u884c\u53c2\u6570\u4f20\u9012\u5750\u6807<\/h3>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u53ef\u4ee5\u4f7f\u7528\u547d\u4ee4\u884c\u53c2\u6570\u4f20\u9012\u70b9\u7684\u5750\u6807\u3002\u4ee5\u4e0b\u793a\u4f8b\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528<code>argparse<\/code>\u5e93\u89e3\u6790\u547d\u4ee4\u884c\u53c2\u6570\u5e76\u83b7\u53d6\u70b9\u7684\u5750\u6807\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import argparse<\/p>\n<h2><strong>\u521b\u5efaArgumentParser\u5bf9\u8c61<\/strong><\/h2>\n<p>parser = argparse.ArgumentParser(description=&quot;\u83b7\u53d6\u70b9\u7684\u5750\u6807&quot;)<\/p>\n<h2><strong>\u6dfb\u52a0\u547d\u4ee4\u884c\u53c2\u6570<\/strong><\/h2>\n<p>parser.add_argument(&#39;--x&#39;, type=float, required=True, help=&quot;x\u5750\u6807&quot;)<\/p>\n<p>parser.add_argument(&#39;--y&#39;, type=float, required=True, help=&quot;y\u5750\u6807&quot;)<\/p>\n<h2><strong>\u89e3\u6790\u547d\u4ee4\u884c\u53c2\u6570<\/strong><\/h2>\n<p>args = parser.parse_args()<\/p>\n<h2><strong>\u83b7\u53d6\u5e76\u6253\u5370\u5750\u6807<\/strong><\/h2>\n<p>x = args.x<\/p>\n<p>y = args.y<\/p>\n<p>print(f&quot;\u547d\u4ee4\u884c\u53c2\u6570\u4e2d\u7684\u70b9\u5750\u6807\u4e3a: ({x}, {y})&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>argparse<\/code>\u5e93\u521b\u5efa\u4e86\u4e00\u4e2a<code>ArgumentParser<\/code>\u5bf9\u8c61\uff0c\u5e76\u6dfb\u52a0\u4e86\u4e24\u4e2a\u547d\u4ee4\u884c\u53c2\u6570<code>--x<\/code>\u548c<code>--y<\/code>\uff0c\u5206\u522b\u8868\u793a\u70b9\u7684x\u548cy\u5750\u6807\u3002\u7136\u540e\uff0c\u6211\u4eec\u89e3\u6790\u547d\u4ee4\u884c\u53c2\u6570\u5e76\u83b7\u53d6\u5750\u6807\u503c\uff0c\u6700\u540e\u6253\u5370\u5750\u6807\u3002<\/p>\n<\/p>\n<p><h3>\u5341\u4e8c\u3001\u4f7f\u7528JSON\u6587\u4ef6\u8bfb\u53d6\u5750\u6807<\/h3>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u5e94\u7528\u4e2d\uff0c\u70b9\u7684\u5750\u6807\u53ef\u80fd\u5b58\u50a8\u5728JSON\u6587\u4ef6\u4e2d\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Python\u7684<code>json<\/code>\u6a21\u5757\u8bfb\u53d6JSON\u6587\u4ef6\u4e2d\u7684\u5750\u6807\u3002\u4ee5\u4e0b\u793a\u4f8b\u5c55\u793a\u4e86\u5982\u4f55\u4eceJSON\u6587\u4ef6\u4e2d\u8bfb\u53d6\u70b9\u7684\u5750\u6807\uff1a<\/p>\n<\/p>\n<p><p>\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u540d\u4e3a<code>points.json<\/code>\u7684\u6587\u4ef6\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-json\">[<\/p>\n<p>    {&quot;x&quot;: 1.2, &quot;y&quot;: 3.4},<\/p>\n<p>    {&quot;x&quot;: 5.6, &quot;y&quot;: 7.8}<\/p>\n<p>]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u8bfb\u53d6JSON\u6587\u4ef6\u4e2d\u7684\u5750\u6807\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import json<\/p>\n<h2><strong>\u6253\u5f00JSON\u6587\u4ef6<\/strong><\/h2>\n<p>with open(&#39;points.json&#39;, &#39;r&#39;) as file:<\/p>\n<p>    points = json.load(file)<\/p>\n<h2><strong>\u6253\u5370\u8bfb\u53d6\u7684\u5750\u6807<\/strong><\/h2>\n<p>for point in points:<\/p>\n<p>    x, y = point[&#39;x&#39;], point[&#39;y&#39;]<\/p>\n<p>    print(f&quot;\u8bfb\u53d6\u7684\u70b9\u5750\u6807\u4e3a: ({x}, {y})&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>json<\/code>\u6a21\u5757\u6253\u5f00\u5e76\u8bfb\u53d6\u540d\u4e3a<code>points.json<\/code>\u7684\u6587\u4ef6\uff0c\u5c06\u5176\u89e3\u6790\u4e3aPython\u5bf9\u8c61\u3002\u7136\u540e\uff0c\u6211\u4eec\u904d\u5386\u89e3\u6790\u540e\u7684\u6570\u636e\u5e76\u6253\u5370\u6bcf\u4e2a\u70b9\u7684\u5750\u6807\u3002<\/p>\n<\/p>\n<p><h3>\u7ed3\u8bba<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u793a\u4f8b\uff0c\u6211\u4eec\u5c55\u793a\u4e86\u591a\u79cd\u5728Python\u4e2d\u8f93\u5165\u548c\u7ba1\u7406\u70b9\u5750\u6807\u7684\u65b9\u6cd5\uff0c\u5305\u62ec\u624b\u52a8\u8f93\u5165\u3001\u51fd\u6570\u4f20\u53c2\u3001\u4ece\u6587\u4ef6\u8bfb\u53d6\u3001\u4f7f\u7528\u56fe\u5f62\u754c\u9762\u3001\u4f7f\u7528\u6570\u636e\u7ed3\u6784\u3001\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\u3001\u4ece\u6570\u636e\u5e93\u8bfb\u53d6\u3001\u4f7f\u7528\u914d\u7f6e\u6587\u4ef6\u3001\u7f51\u7edc\u8bf7\u6c42\u3001\u73af\u5883\u53d8\u91cf\u3001\u547d\u4ee4\u884c\u53c2\u6570\u548cJSON\u6587\u4ef6\u3002\u4e0d\u540c\u7684\u65b9\u6cd5\u9002\u7528\u4e8e\u4e0d\u540c\u7684\u5e94\u7528\u573a\u666f\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u6765\u5904\u7406\u70b9\u7684\u5750\u6807\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u8f93\u5165\u4e8c\u7ef4\u5750\u6807\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u5185\u7f6e\u7684input()\u51fd\u6570\u6765\u8f93\u5165\u5750\u6807\u3002\u7528\u6237\u53ef\u4ee5\u901a\u8fc7\u8f93\u5165\u5b57\u7b26\u4e32\u5f62\u5f0f\u7684\u5750\u6807\uff0c\u7136\u540e\u4f7f\u7528split()\u65b9\u6cd5\u5c06\u5176\u5206\u5272\u6210\u4e24\u4e2a\u90e8\u5206\uff0c\u5206\u522b\u8868\u793ax\u548cy\u5750\u6807\u3002\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a  <\/p>\n<pre><code class=\"language-python\">coordinates = input(&quot;\u8bf7\u8f93\u5165\u70b9\u7684\u5750\u6807\uff08\u683c\u5f0f\uff1ax,y\uff09\uff1a&quot;)\nx, y = map(float, coordinates.split(&#39;,&#39;))\nprint(f&quot;x\u5750\u6807\u4e3a: {x}, y\u5750\u6807\u4e3a: {y}&quot;)\n<\/code><\/pre>\n<p>\u8fd9\u6837\uff0c\u7528\u6237\u53ef\u4ee5\u65b9\u4fbf\u5730\u8f93\u5165\u5750\u6807\uff0c\u7a0b\u5e8f\u4e5f\u4f1a\u5c06\u5176\u8f6c\u6362\u4e3a\u6d6e\u70b9\u6570\uff0c\u4fbf\u4e8e\u540e\u7eed\u8ba1\u7b97\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u5982\u4f55\u9a8c\u8bc1\u8f93\u5165\u7684\u5750\u6807\u683c\u5f0f\uff1f<\/strong><br \/>\u4e3a\u4e86\u786e\u4fdd\u7528\u6237\u8f93\u5165\u7684\u5750\u6807\u683c\u5f0f\u6b63\u786e\uff0c\u53ef\u4ee5\u4f7f\u7528try-except\u8bed\u53e5\u6765\u6355\u83b7\u53ef\u80fd\u53d1\u751f\u7684\u5f02\u5e38\u3002\u901a\u8fc7\u6b63\u5219\u8868\u8fbe\u5f0f\u4e5f\u53ef\u4ee5\u8fdb\u4e00\u6b65\u9a8c\u8bc1\u8f93\u5165\u7684\u6709\u6548\u6027\u3002\u4f8b\u5982\uff1a  <\/p>\n<pre><code class=\"language-python\">import re\n\ndef validate_coordinates(coordinates):\n    pattern = r&quot;^-?\\d+(\\.\\d+)?,-?\\d+(\\.\\d+)?$&quot;\n    if re.match(pattern, coordinates):\n        return True\n    return False\n\ncoordinates = input(&quot;\u8bf7\u8f93\u5165\u70b9\u7684\u5750\u6807\uff08\u683c\u5f0f\uff1ax,y\uff09\uff1a&quot;)\nif validate_coordinates(coordinates):\n    x, y = map(float, coordinates.split(&#39;,&#39;))\n    print(f&quot;x\u5750\u6807\u4e3a: {x}, y\u5750\u6807\u4e3a: {y}&quot;)\nelse:\n    print(&quot;\u8f93\u5165\u683c\u5f0f\u4e0d\u6b63\u786e\uff0c\u8bf7\u4f7f\u7528\u683c\u5f0f x,y \u8f93\u5165\u5750\u6807\u3002&quot;)\n<\/code><\/pre>\n<p>\u8fd9\u4e2a\u65b9\u6cd5\u786e\u4fdd\u7528\u6237\u8f93\u5165\u7684\u5750\u6807\u7b26\u5408\u9884\u671f\u683c\u5f0f\uff0c\u4ece\u800c\u51cf\u5c11\u9519\u8bef\u3002<\/p>\n<p><strong>\u5982\u4f55\u5c06\u8f93\u5165\u7684\u5750\u6807\u7528\u4e8e\u7ed8\u56fe\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528matplotlib\u5e93\u5c06\u8f93\u5165\u7684\u5750\u6807\u53ef\u89c6\u5316\u3002\u7528\u6237\u53ef\u4ee5\u5148\u8f93\u5165\u5750\u6807\uff0c\u7136\u540e\u4f7f\u7528matplotlib\u7ed8\u5236\u70b9\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u793a\u4f8b\uff1a  <\/p>\n<pre><code class=\"language-python\">import matplotlib.pyplot as plt\n\ncoordinates = input(&quot;\u8bf7\u8f93\u5165\u70b9\u7684\u5750\u6807\uff08\u683c\u5f0f\uff1ax,y\uff09\uff1a&quot;)\nx, y = map(float, coordinates.split(&#39;,&#39;))\n\nplt.plot(x, y, &#39;ro&#39;)  # &#39;ro&#39;\u8868\u793a\u7ea2\u8272\u5706\u70b9\nplt.xlim(-10, 10)\nplt.ylim(-10, 10)\nplt.title(&quot;\u8f93\u5165\u7684\u5750\u6807\u70b9&quot;)\nplt.xlabel(&quot;X\u8f74&quot;)\nplt.ylabel(&quot;Y\u8f74&quot;)\nplt.grid()\nplt.show()\n<\/code><\/pre>\n<p>\u6b64\u4ee3\u7801\u5c06\u663e\u793a\u4e00\u4e2a\u5305\u542b\u8f93\u5165\u5750\u6807\u70b9\u7684\u56fe\u5f62\uff0c\u4fbf\u4e8e\u7528\u6237\u76f4\u89c2\u7406\u89e3\u5176\u4f4d\u7f6e\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u4e2d\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u8f93\u5165\u70b9\u7684\u5750\u6807\uff0c\u4f8b\u5982\uff1a\u624b\u52a8\u8f93\u5165\u3001\u901a\u8fc7\u51fd\u6570\u4f20\u53c2\u3001\u4ece\u6587\u4ef6\u8bfb\u53d6\u7b49\u3002\u6700\u5e38\u7528\u7684\u65b9\u5f0f\u5305\u62ec\uff1a\u4f7f\u7528 [&hellip;]","protected":false},"author":3,"featured_media":1075537,"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\/1075530"}],"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=1075530"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1075530\/revisions"}],"predecessor-version":[{"id":1075538,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1075530\/revisions\/1075538"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1075537"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1075530"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1075530"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1075530"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}