{"id":1147971,"date":"2025-01-13T16:31:31","date_gmt":"2025-01-13T08:31:31","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1147971.html"},"modified":"2025-01-13T16:31:33","modified_gmt":"2025-01-13T08:31:33","slug":"python%e5%a6%82%e4%bd%95%e7%94%a8%e8%af%ad%e8%a8%80","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1147971.html","title":{"rendered":"python\u5982\u4f55\u7528\u8bed\u8a00"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25170124\/51a0e44b-6b8e-4c0b-82a1-a82199bbf730.webp\" alt=\"python\u5982\u4f55\u7528\u8bed\u8a00\" \/><\/p>\n<p><p> Python\u662f\u4e00\u79cd\u9ad8\u7ea7\u7f16\u7a0b\u8bed\u8a00\uff0c\u5e7f\u6cdb\u7528\u4e8eWeb\u5f00\u53d1\u3001\u6570\u636e\u5206\u6790\u3001<a href=\"https:\/\/docs.pingcode.com\/tag\/AI\" target=\"_blank\">\u4eba\u5de5\u667a\u80fd<\/a>\u548c\u81ea\u52a8\u5316\u4efb\u52a1\u7b49\u9886\u57df\u3002<strong>Python\u53ef\u4ee5\u901a\u8fc7\u5b9a\u4e49\u51fd\u6570\u3001\u7c7b\u548c\u6a21\u5757\u3001\u4f7f\u7528\u5185\u7f6e\u5e93\u548c\u7b2c\u4e09\u65b9\u5e93\u3001\u7f16\u5199\u811a\u672c\u548c\u547d\u4ee4\u884c\u7a0b\u5e8f\u3001\u5f00\u53d1Web\u5e94\u7528\u7a0b\u5e8f\u4ee5\u53ca\u8fdb\u884c\u6570\u636e\u5206\u6790\u548c\u53ef\u89c6\u5316\u7b49\u65b9\u5f0f\u6765\u8fdb\u884c\u7f16\u7a0b<\/strong>\u3002\u5728\u8fd9\u4e9b\u529f\u80fd\u4e2d\uff0c\u5b9a\u4e49\u51fd\u6570\u548c\u7c7b\u662f\u6700\u57fa\u7840\u4e5f\u662f\u6700\u91cd\u8981\u7684\u6280\u80fd\u4e4b\u4e00\u3002\u51fd\u6570\u548c\u7c7b\u4e0d\u4ec5\u80fd\u591f\u63d0\u9ad8\u4ee3\u7801\u7684\u91cd\u7528\u6027\uff0c\u8fd8\u80fd\u4f7f\u4ee3\u7801\u66f4\u52a0\u7b80\u6d01\u6613\u8bfb\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u5c06\u8be6\u7ec6\u89e3\u91ca\u5982\u4f55\u5728Python\u4e2d\u5b9a\u4e49\u548c\u4f7f\u7528\u51fd\u6570\u3002<\/p>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u51fd\u6570\u662f\u901a\u8fc7\u5173\u952e\u5b57<code>def<\/code>\u6765\u5b9a\u4e49\u7684\u3002\u51fd\u6570\u53ef\u4ee5\u63a5\u53d7\u53c2\u6570\uff0c\u5e76\u8fd4\u56de\u4e00\u4e2a\u503c\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def greet(name):<\/p>\n<p>    return f&quot;Hello, {name}!&quot;<\/p>\n<p>print(greet(&quot;Alice&quot;))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a\u540d\u4e3a<code>greet<\/code>\u7684\u51fd\u6570\uff0c\u5b83\u63a5\u53d7\u4e00\u4e2a\u53c2\u6570<code>name<\/code>\uff0c\u5e76\u8fd4\u56de\u4e00\u4e2a\u95ee\u5019\u5b57\u7b26\u4e32\u3002\u901a\u8fc7\u8c03\u7528<code>greet<\/code>\u51fd\u6570\u5e76\u4f20\u5165\u53c2\u6570\uff0c\u6211\u4eec\u53ef\u4ee5\u5f97\u5230\u76f8\u5e94\u7684\u8f93\u51fa\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u5b9a\u4e49\u548c\u4f7f\u7528\u51fd\u6570<\/h3>\n<\/p>\n<p><h4>1\u3001\u57fa\u672c\u51fd\u6570\u5b9a\u4e49<\/h4>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u51fd\u6570\u662f\u901a\u8fc7<code>def<\/code>\u5173\u952e\u5b57\u5b9a\u4e49\u7684\u3002\u57fa\u672c\u7684\u51fd\u6570\u5b9a\u4e49\u5f62\u5f0f\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def function_name(parameters):<\/p>\n<p>    &quot;&quot;&quot;docstring&quot;&quot;&quot;<\/p>\n<p>    statement(s)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5176\u4e2d\uff0c<code>function_name<\/code>\u662f\u51fd\u6570\u7684\u540d\u79f0\uff0c<code>parameters<\/code>\u662f\u51fd\u6570\u7684\u53c2\u6570\u5217\u8868\uff0c<code>docstring<\/code>\u662f\u51fd\u6570\u7684\u6587\u6863\u5b57\u7b26\u4e32\uff08\u53ef\u9009\uff09\uff0c<code>statement(s)<\/code>\u662f\u51fd\u6570\u7684\u8bed\u53e5\u5757\u3002<\/p>\n<\/p>\n<p><p>\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def add(a, b):<\/p>\n<p>    &quot;&quot;&quot;\u8fd4\u56de\u4e24\u4e2a\u6570\u7684\u548c&quot;&quot;&quot;<\/p>\n<p>    return a + b<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u51fd\u6570\u7684\u8c03\u7528<\/h4>\n<\/p>\n<p><p>\u5b9a\u4e49\u51fd\u6570\u4e4b\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u51fd\u6570\u540d\u79f0\u548c\u53c2\u6570\u6765\u8c03\u7528\u51fd\u6570\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">result = add(3, 5)<\/p>\n<p>print(result)  # \u8f93\u51fa: 8<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001\u9ed8\u8ba4\u53c2\u6570\u503c<\/h4>\n<\/p>\n<p><p>Python\u5141\u8bb8\u5728\u51fd\u6570\u5b9a\u4e49\u65f6\u4e3a\u53c2\u6570\u6307\u5b9a\u9ed8\u8ba4\u503c\u3002\u5982\u679c\u8c03\u7528\u51fd\u6570\u65f6\u6ca1\u6709\u4f20\u9012\u5bf9\u5e94\u7684\u53c2\u6570\uff0c\u5219\u4f7f\u7528\u9ed8\u8ba4\u503c\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def greet(name, message=&quot;Hello&quot;):<\/p>\n<p>    return f&quot;{message}, {name}!&quot;<\/p>\n<p>print(greet(&quot;Alice&quot;))  # \u8f93\u51fa: Hello, Alice!<\/p>\n<p>print(greet(&quot;Bob&quot;, &quot;Hi&quot;))  # \u8f93\u51fa: Hi, Bob!<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e8c\u3001\u5b9a\u4e49\u548c\u4f7f\u7528\u7c7b<\/h3>\n<\/p>\n<p><h4>1\u3001\u57fa\u672c\u7c7b\u5b9a\u4e49<\/h4>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u7c7b\u662f\u901a\u8fc7<code>class<\/code>\u5173\u952e\u5b57\u5b9a\u4e49\u7684\u3002\u57fa\u672c\u7684\u7c7b\u5b9a\u4e49\u5f62\u5f0f\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">class ClassName:<\/p>\n<p>    &quot;&quot;&quot;docstring&quot;&quot;&quot;<\/p>\n<p>    attribute = value<\/p>\n<p>    def __init__(self, parameters):<\/p>\n<p>        self.attribute = value<\/p>\n<p>    def method(self, parameters):<\/p>\n<p>        statement(s)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5176\u4e2d\uff0c<code>ClassName<\/code>\u662f\u7c7b\u7684\u540d\u79f0\uff0c<code>attribute<\/code>\u662f\u7c7b\u7684\u5c5e\u6027\uff0c<code>__init__<\/code>\u662f\u7c7b\u7684\u6784\u9020\u51fd\u6570\uff0c<code>method<\/code>\u662f\u7c7b\u7684\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><p>\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">class Dog:<\/p>\n<p>    &quot;&quot;&quot;\u72d7\u7c7b&quot;&quot;&quot;<\/p>\n<p>    species = &quot;Canis familiaris&quot;<\/p>\n<p>    def __init__(self, name, age):<\/p>\n<p>        self.name = name<\/p>\n<p>        self.age = age<\/p>\n<p>    def bark(self):<\/p>\n<p>        return f&quot;{self.name} says woof!&quot;<\/p>\n<h2><strong>\u521b\u5efaDog\u7c7b\u7684\u5b9e\u4f8b<\/strong><\/h2>\n<p>my_dog = Dog(&quot;Buddy&quot;, 3)<\/p>\n<p>print(my_dog.bark())  # \u8f93\u51fa: Buddy says woof!<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u7ee7\u627f\u548c\u591a\u6001<\/h4>\n<\/p>\n<p><p>Python\u652f\u6301\u7c7b\u7684\u7ee7\u627f\u548c\u591a\u6001\u3002\u53ef\u4ee5\u901a\u8fc7\u5b9a\u4e49\u4e00\u4e2a\u57fa\u7c7b\uff0c\u5e76\u8ba9\u5176\u4ed6\u7c7b\u7ee7\u627f\u5b83\u6765\u5b9e\u73b0\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">class Animal:<\/p>\n<p>    def __init__(self, name):<\/p>\n<p>        self.name = name<\/p>\n<p>    def speak(self):<\/p>\n<p>        r<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>se NotImplementedError(&quot;Subclass must implement abstract method&quot;)<\/p>\n<p>class Dog(Animal):<\/p>\n<p>    def speak(self):<\/p>\n<p>        return f&quot;{self.name} says woof!&quot;<\/p>\n<p>class Cat(Animal):<\/p>\n<p>    def speak(self):<\/p>\n<p>        return f&quot;{self.name} says meow!&quot;<\/p>\n<p>animals = [Dog(&quot;Buddy&quot;), Cat(&quot;Whiskers&quot;)]<\/p>\n<p>for animal in animals:<\/p>\n<p>    print(animal.speak())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c<code>Animal<\/code>\u7c7b\u662f\u4e00\u4e2a\u57fa\u7c7b\uff0c<code>Dog<\/code>\u7c7b\u548c<code>Cat<\/code>\u7c7b\u7ee7\u627f\u81ea<code>Animal<\/code>\u7c7b\uff0c\u5e76\u5b9e\u73b0\u4e86<code>Animal<\/code>\u7c7b\u7684\u62bd\u8c61\u65b9\u6cd5<code>speak<\/code>\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528\u5185\u7f6e\u5e93\u548c\u7b2c\u4e09\u65b9\u5e93<\/h3>\n<\/p>\n<p><h4>1\u3001Python\u5185\u7f6e\u5e93<\/h4>\n<\/p>\n<p><p>Python\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u5185\u7f6e\u5e93\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u5b8c\u6210\u5404\u79cd\u5e38\u89c1\u4efb\u52a1\u3002\u4f8b\u5982\uff0c\u4f7f\u7528<code>math<\/code>\u5e93\u8fdb\u884c\u6570\u5b66\u8fd0\u7b97\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import math<\/p>\n<p>print(math.sqrt(16))  # \u8f93\u51fa: 4.0<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u7b2c\u4e09\u65b9\u5e93<\/h4>\n<\/p>\n<p><p>\u9664\u4e86\u5185\u7f6e\u5e93\u4e4b\u5916\uff0cPython\u8fd8\u652f\u6301\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93\u3002\u53ef\u4ee5\u901a\u8fc7<code>pip<\/code>\u5de5\u5177\u6765\u5b89\u88c5\u548c\u7ba1\u7406\u7b2c\u4e09\u65b9\u5e93\u3002\u4f8b\u5982\uff0c\u4f7f\u7528<code>requests<\/code>\u5e93\u8fdb\u884cHTTP\u8bf7\u6c42\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import requests<\/p>\n<p>response = requests.get(&quot;https:\/\/api.github.com&quot;)<\/p>\n<p>print(response.json())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u7f16\u5199\u811a\u672c\u548c\u547d\u4ee4\u884c\u7a0b\u5e8f<\/h3>\n<\/p>\n<p><h4>1\u3001Python\u811a\u672c<\/h4>\n<\/p>\n<p><p>Python\u811a\u672c\u662f\u4e00\u4e2a\u5305\u542bPython\u4ee3\u7801\u7684\u6587\u4ef6\uff0c\u901a\u5e38\u4ee5<code>.py<\/code>\u6269\u5c55\u540d\u7ed3\u5c3e\u3002\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4\u884c\u8fd0\u884cPython\u811a\u672c\u3002\u4f8b\u5982\uff0c\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a<code>script.py<\/code>\u7684\u6587\u4ef6\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">print(&quot;Hello, World!&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\u5728\u547d\u4ee4\u884c\u4e2d\u8fd0\u884c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-sh\">python script.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u547d\u4ee4\u884c\u53c2\u6570<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u901a\u8fc7<code>sys.argv<\/code>\u83b7\u53d6\u547d\u4ee4\u884c\u53c2\u6570\u3002\u4f8b\u5982\uff0c\u4fee\u6539<code>script.py<\/code>\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import sys<\/p>\n<p>if len(sys.argv) &lt; 2:<\/p>\n<p>    print(&quot;Usage: python script.py &lt;name&gt;&quot;)<\/p>\n<p>else:<\/p>\n<p>    name = sys.argv[1]<\/p>\n<p>    print(f&quot;Hello, {name}!&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\u5728\u547d\u4ee4\u884c\u4e2d\u8fd0\u884c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-sh\">python script.py Alice<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e94\u3001\u5f00\u53d1Web\u5e94\u7528\u7a0b\u5e8f<\/h3>\n<\/p>\n<p><h4>1\u3001\u4f7f\u7528Flask\u6846\u67b6<\/h4>\n<\/p>\n<p><p>Flask\u662f\u4e00\u4e2a\u8f7b\u91cf\u7ea7\u7684Web\u6846\u67b6\uff0c\u53ef\u4ee5\u5feb\u901f\u5f00\u53d1Web\u5e94\u7528\u7a0b\u5e8f\u3002\u9996\u5148\uff0c\u901a\u8fc7<code>pip<\/code>\u5b89\u88c5Flask\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-sh\">pip install Flask<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a<code>app.py<\/code>\u7684\u6587\u4ef6\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from flask import Flask<\/p>\n<p>app = Flask(__name__)<\/p>\n<p>@app.route(&quot;\/&quot;)<\/p>\n<p>def home():<\/p>\n<p>    return &quot;Hello, Flask!&quot;<\/p>\n<p>if __name__ == &quot;__main__&quot;:<\/p>\n<p>    app.run(debug=True)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd0\u884c<code>app.py<\/code>\uff0c\u7136\u540e\u5728\u6d4f\u89c8\u5668\u4e2d\u8bbf\u95ee<code>http:\/\/127.0.0.1:5000\/<\/code>\uff0c\u5c06\u770b\u5230&quot;Hello, Flask!&quot;\u7684\u8f93\u51fa\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u4f7f\u7528Django\u6846\u67b6<\/h4>\n<\/p>\n<p><p>Django\u662f\u4e00\u4e2a\u529f\u80fd\u5f3a\u5927\u7684Web\u6846\u67b6\uff0c\u9002\u7528\u4e8e\u5f00\u53d1\u590d\u6742\u7684Web\u5e94\u7528\u7a0b\u5e8f\u3002\u9996\u5148\uff0c\u901a\u8fc7<code>pip<\/code>\u5b89\u88c5Django\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-sh\">pip install Django<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\u521b\u5efa\u4e00\u4e2aDjango\u9879\u76ee\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-sh\">django-admin startproject myproject<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fdb\u5165\u9879\u76ee\u76ee\u5f55\u5e76\u542f\u52a8\u5f00\u53d1\u670d\u52a1\u5668\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-sh\">cd myproject<\/p>\n<p>python manage.py runserver<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u6d4f\u89c8\u5668\u4e2d\u8bbf\u95ee<code>http:\/\/127.0.0.1:8000\/<\/code>\uff0c\u5c06\u770b\u5230Django\u7684\u6b22\u8fce\u9875\u9762\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u6570\u636e\u5206\u6790\u548c\u53ef\u89c6\u5316<\/h3>\n<\/p>\n<p><h4>1\u3001\u4f7f\u7528Pandas\u8fdb\u884c\u6570\u636e\u5206\u6790<\/h4>\n<\/p>\n<p><p>Pandas\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u6570\u636e\u5206\u6790\u5e93\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u5904\u7406\u6570\u636e\u96c6\u3002\u9996\u5148\uff0c\u901a\u8fc7<code>pip<\/code>\u5b89\u88c5Pandas\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-sh\">pip install pandas<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\u4f7f\u7528Pandas\u8bfb\u53d6\u548c\u5904\u7406\u6570\u636e\u3002\u4f8b\u5982\uff0c\u8bfb\u53d6\u4e00\u4e2aCSV\u6587\u4ef6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>data = pd.read_csv(&quot;data.csv&quot;)<\/p>\n<p>print(data.head())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u4f7f\u7528Matplotlib\u8fdb\u884c\u6570\u636e\u53ef\u89c6\u5316<\/h4>\n<\/p>\n<p><p>Matplotlib\u662f\u4e00\u4e2a\u5e38\u7528\u7684\u6570\u636e\u53ef\u89c6\u5316\u5e93\u3002\u9996\u5148\uff0c\u901a\u8fc7<code>pip<\/code>\u5b89\u88c5Matplotlib\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-sh\">pip install matplotlib<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\u4f7f\u7528Matplotlib\u7ed8\u5236\u56fe\u8868\u3002\u4f8b\u5982\uff0c\u7ed8\u5236\u4e00\u4e2a\u7b80\u5355\u7684\u6298\u7ebf\u56fe\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>x = [1, 2, 3, 4, 5]<\/p>\n<p>y = [2, 3, 5, 7, 11]<\/p>\n<p>plt.plot(x, y)<\/p>\n<p>plt.xlabel(&quot;X-axis&quot;)<\/p>\n<p>plt.ylabel(&quot;Y-axis&quot;)<\/p>\n<p>plt.title(&quot;Simple Line Plot&quot;)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e03\u3001\u81ea\u52a8\u5316\u4efb\u52a1<\/h3>\n<\/p>\n<p><h4>1\u3001\u4f7f\u7528Selenium\u8fdb\u884cWeb\u81ea\u52a8\u5316<\/h4>\n<\/p>\n<p><p>Selenium\u662f\u4e00\u4e2a\u7528\u4e8eWeb\u81ea\u52a8\u5316\u6d4b\u8bd5\u7684\u5e93\u3002\u9996\u5148\uff0c\u901a\u8fc7<code>pip<\/code>\u5b89\u88c5Selenium\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-sh\">pip install selenium<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\u4f7f\u7528Selenium\u8fdb\u884cWeb\u81ea\u52a8\u5316\u3002\u4f8b\u5982\uff0c\u6253\u5f00\u4e00\u4e2a\u7f51\u9875\u5e76\u83b7\u53d6\u6807\u9898\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from selenium import webdriver<\/p>\n<p>driver = webdriver.Chrome()<\/p>\n<p>driver.get(&quot;https:\/\/www.google.com&quot;)<\/p>\n<p>print(driver.title)<\/p>\n<p>driver.quit()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u4f7f\u7528OpenCV\u8fdb\u884c\u56fe\u50cf\u5904\u7406<\/h4>\n<\/p>\n<p><p>OpenCV\u662f\u4e00\u4e2a\u5f00\u6e90\u7684\u8ba1\u7b97\u673a\u89c6\u89c9\u5e93\u3002\u9996\u5148\uff0c\u901a\u8fc7<code>pip<\/code>\u5b89\u88c5OpenCV\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-sh\">pip install opencv-python<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\u4f7f\u7528OpenCV\u8fdb\u884c\u56fe\u50cf\u5904\u7406\u3002\u4f8b\u5982\uff0c\u8bfb\u53d6\u548c\u663e\u793a\u56fe\u50cf\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import cv2<\/p>\n<p>image = cv2.imread(&quot;image.jpg&quot;)<\/p>\n<p>cv2.imshow(&quot;Image&quot;, image)<\/p>\n<p>cv2.waitKey(0)<\/p>\n<p>cv2.destroyAllWindows()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u516b\u3001<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\u548c\u4eba\u5de5\u667a\u80fd<\/h3>\n<\/p>\n<p><h4>1\u3001\u4f7f\u7528Scikit-learn\u8fdb\u884c\u673a\u5668\u5b66\u4e60<\/h4>\n<\/p>\n<p><p>Scikit-learn\u662f\u4e00\u4e2a\u5e38\u7528\u7684\u673a\u5668\u5b66\u4e60\u5e93\u3002\u9996\u5148\uff0c\u901a\u8fc7<code>pip<\/code>\u5b89\u88c5Scikit-learn\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-sh\">pip install scikit-learn<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\u4f7f\u7528Scikit-learn\u8fdb\u884c\u673a\u5668\u5b66\u4e60\u3002\u4f8b\u5982\uff0c\u8bad\u7ec3\u4e00\u4e2a\u7b80\u5355\u7684\u7ebf\u6027\u56de\u5f52\u6a21\u578b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from sklearn.linear_model import LinearRegression<\/p>\n<p>import numpy as np<\/p>\n<p>X = np.array([[1], [2], [3], [4], [5]])<\/p>\n<p>y = np.array([2, 3, 5, 7, 11])<\/p>\n<p>model = LinearRegression()<\/p>\n<p>model.fit(X, y)<\/p>\n<p>print(model.predict([[6]]))  # \u8f93\u51fa: [13.]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u4f7f\u7528TensorFlow\u8fdb\u884c\u6df1\u5ea6\u5b66\u4e60<\/h4>\n<\/p>\n<p><p>TensorFlow\u662f\u4e00\u4e2a\u5e7f\u6cdb\u4f7f\u7528\u7684\u6df1\u5ea6\u5b66\u4e60\u6846\u67b6\u3002\u9996\u5148\uff0c\u901a\u8fc7<code>pip<\/code>\u5b89\u88c5TensorFlow\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-sh\">pip install tensorflow<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\u4f7f\u7528TensorFlow\u6784\u5efa\u548c\u8bad\u7ec3\u6df1\u5ea6\u5b66\u4e60\u6a21\u578b\u3002\u4f8b\u5982\uff0c\u6784\u5efa\u4e00\u4e2a\u7b80\u5355\u7684\u795e\u7ecf\u7f51\u7edc\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import tensorflow as tf<\/p>\n<p>from tensorflow.keras.models import Sequential<\/p>\n<p>from tensorflow.keras.layers import Dense<\/p>\n<p>model = Sequential([<\/p>\n<p>    Dense(64, activation=&#39;relu&#39;, input_shape=(10,)),<\/p>\n<p>    Dense(64, activation=&#39;relu&#39;),<\/p>\n<p>    Dense(1, activation=&#39;sigmoid&#39;)<\/p>\n<p>])<\/p>\n<p>model.compile(optimizer=&#39;adam&#39;, loss=&#39;binary_crossentropy&#39;, metrics=[&#39;accuracy&#39;])<\/p>\n<h2><strong>\u751f\u6210\u4e00\u4e9b\u968f\u673a\u6570\u636e\u8fdb\u884c\u8bad\u7ec3<\/strong><\/h2>\n<p>import numpy as np<\/p>\n<p>X_train = np.random.rand(1000, 10)<\/p>\n<p>y_train = np.random.randint(2, size=(1000, 1))<\/p>\n<p>model.fit(X_train, y_train, epochs=10)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e5d\u3001\u5f00\u53d1\u56fe\u5f62\u7528\u6237\u754c\u9762\uff08GUI\uff09\u5e94\u7528\u7a0b\u5e8f<\/h3>\n<\/p>\n<p><h4>1\u3001\u4f7f\u7528Tkinter\u5f00\u53d1GUI\u5e94\u7528\u7a0b\u5e8f<\/h4>\n<\/p>\n<p><p>Tkinter\u662fPython\u7684\u6807\u51c6GUI\u5e93\u3002\u53ef\u4ee5\u4f7f\u7528Tkinter\u5feb\u901f\u5f00\u53d1GUI\u5e94\u7528\u7a0b\u5e8f\u3002\u4f8b\u5982\uff0c\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684\u7a97\u53e3\uff1a<\/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;Hello Tkinter&quot;)<\/p>\n<p>label = tk.Label(root, text=&quot;Hello, Tkinter!&quot;)<\/p>\n<p>label.pack()<\/p>\n<p>root.mainloop()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u4f7f\u7528PyQt\u5f00\u53d1GUI\u5e94\u7528\u7a0b\u5e8f<\/h4>\n<\/p>\n<p><p>PyQt\u662f\u4e00\u4e2a\u529f\u80fd\u5f3a\u5927\u7684GUI\u5e93\u3002\u9996\u5148\uff0c\u901a\u8fc7<code>pip<\/code>\u5b89\u88c5PyQt\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-sh\">pip install PyQt5<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\u4f7f\u7528PyQt\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684\u7a97\u53e3\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import sys<\/p>\n<p>from PyQt5.QtWidgets import QApplication, QLabel, QWidget<\/p>\n<p>app = QApplication(sys.argv)<\/p>\n<p>window = QWidget()<\/p>\n<p>window.setWindowTitle(&#39;Hello PyQt&#39;)<\/p>\n<p>window.setGeometry(100, 100, 280, 80)<\/p>\n<p>label = QLabel(&#39;&lt;h1&gt;Hello, PyQt!&lt;\/h1&gt;&#39;, parent=window)<\/p>\n<p>label.move(60, 15)<\/p>\n<p>window.show()<\/p>\n<p>sys.exit(app.exec_())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u5341\u3001\u7f51\u7edc\u7f16\u7a0b<\/h3>\n<\/p>\n<p><h4>1\u3001\u4f7f\u7528Socket\u7f16\u7a0b<\/h4>\n<\/p>\n<p><p>Python\u63d0\u4f9b\u4e86<code>socket<\/code>\u5e93\u7528\u4e8e\u7f51\u7edc\u7f16\u7a0b\u3002\u53ef\u4ee5\u4f7f\u7528<code>socket<\/code>\u5e93\u521b\u5efa\u5ba2\u6237\u7aef\u548c\u670d\u52a1\u5668\u3002\u4f8b\u5982\uff0c\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684TCP\u670d\u52a1\u5668\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import socket<\/p>\n<p>server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)<\/p>\n<p>server_socket.bind((&#39;localhost&#39;, 12345))<\/p>\n<p>server_socket.listen(5)<\/p>\n<p>print(&quot;Server is listening...&quot;)<\/p>\n<p>while True:<\/p>\n<p>    client_socket, addr = server_socket.accept()<\/p>\n<p>    print(f&quot;Connection from {addr}&quot;)<\/p>\n<p>    client_socket.sendall(b&quot;Hello, client!&quot;)<\/p>\n<p>    client_socket.close()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684TCP\u5ba2\u6237\u7aef\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import socket<\/p>\n<p>client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)<\/p>\n<p>client_socket.connect((&#39;localhost&#39;, 12345))<\/p>\n<p>message = client_socket.recv(1024)<\/p>\n<p>print(message.decode())<\/p>\n<p>client_socket.close()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u4f7f\u7528HTTP\u7f16\u7a0b<\/h4>\n<\/p>\n<p><p>Python\u63d0\u4f9b\u4e86<code>http.server<\/code>\u5e93\u7528\u4e8e\u521b\u5efaHTTP\u670d\u52a1\u5668\u3002\u4f8b\u5982\uff0c\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684HTTP\u670d\u52a1\u5668\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from http.server import BaseHTTPRequestHandler, HTTPServer<\/p>\n<p>class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):<\/p>\n<p>    def do_GET(self):<\/p>\n<p>        self.send_response(200)<\/p>\n<p>        self.send_header(&quot;Content-type&quot;, &quot;text\/html&quot;)<\/p>\n<p>        self.end_headers()<\/p>\n<p>        self.wfile.write(b&quot;Hello, HTTP!&quot;)<\/p>\n<p>server = HTTPServer((&#39;localhost&#39;, 8080), SimpleHTTPRequestHandler)<\/p>\n<p>print(&quot;Server is running...&quot;)<\/p>\n<p>server.serve_forever()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u5341\u4e00\u3001\u6587\u4ef6\u548c\u76ee\u5f55\u64cd\u4f5c<\/h3>\n<\/p>\n<p><h4>1\u3001\u8bfb\u53d6\u548c\u5199\u5165\u6587\u4ef6<\/h4>\n<\/p>\n<p><p>Python\u63d0\u4f9b\u4e86\u5185\u7f6e\u7684<code>open<\/code>\u51fd\u6570\u7528\u4e8e\u8bfb\u53d6\u548c\u5199\u5165\u6587\u4ef6\u3002\u4f8b\u5982\uff0c\u8bfb\u53d6\u6587\u4ef6\u7684\u5185\u5bb9\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">with open(&quot;example.txt&quot;, &quot;r&quot;) as file:<\/p>\n<p>    content = file.read()<\/p>\n<p>    print(content)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5199\u5165\u6587\u4ef6\u7684\u5185\u5bb9\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">with open(&quot;example.txt&quot;, &quot;w&quot;) as file:<\/p>\n<p>    file.write(&quot;Hello, World!&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u64cd\u4f5c\u76ee\u5f55<\/h4>\n<\/p>\n<p><p>Python\u63d0\u4f9b\u4e86<code>os<\/code>\u548c<code>shutil<\/code>\u5e93\u7528\u4e8e\u64cd\u4f5c\u76ee\u5f55\u3002\u4f8b\u5982\uff0c\u5217\u51fa\u76ee\u5f55\u4e2d\u7684\u6587\u4ef6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import os<\/p>\n<p>files = os.listdir(&quot;.&quot;)<\/p>\n<p>print(files)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u521b\u5efa\u548c\u5220\u9664\u76ee\u5f55\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import os<\/p>\n<p>os.mkdir(&quot;new_directory&quot;)<\/p>\n<p>os.rmdir(&quot;new_directory&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u5341\u4e8c\u3001\u9519\u8bef\u548c\u5f02\u5e38\u5904\u7406<\/h3>\n<\/p>\n<p><h4>1\u3001\u6355\u83b7\u5f02\u5e38<\/h4>\n<\/p>\n<p><p>Python\u63d0\u4f9b\u4e86<code>try<\/code>\u548c<code>except<\/code>\u5757\u7528\u4e8e\u6355\u83b7\u5f02\u5e38\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">try:<\/p>\n<p>    result = 10 \/ 0<\/p>\n<p>except ZeroDivisionError:<\/p>\n<p>    print(&quot;\u4e0d\u80fd\u9664\u4ee5\u96f6&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u629b\u51fa\u5f02\u5e38<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528<code>raise<\/code>\u5173\u952e\u5b57\u629b\u51fa\u5f02\u5e38\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def divide(a, b):<\/p>\n<p>    if b == 0:<\/p>\n<p>        raise ValueError(&quot;\u4e0d\u80fd\u9664\u4ee5\u96f6&quot;)<\/p>\n<p>    return a \/ b<\/p>\n<p>try:<\/p>\n<p>    divide(10, 0)<\/p>\n<p>except ValueError as e:<\/p>\n<p>    print(e)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u5341\u4e09\u3001\u5355\u5143\u6d4b\u8bd5<\/h3>\n<\/p>\n<p><h4>1\u3001\u4f7f\u7528unittest\u8fdb\u884c\u5355\u5143\u6d4b\u8bd5<\/h4>\n<\/p>\n<p><p>Python\u63d0\u4f9b\u4e86<code>unittest<\/code>\u6a21\u5757\u7528\u4e8e\u7f16\u5199\u548c\u8fd0\u884c\u5355\u5143\u6d4b\u8bd5\u3002\u4f8b\u5982\uff0c\u7f16\u5199\u4e00\u4e2a\u7b80\u5355\u7684\u6d4b\u8bd5\u7528\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import unittest<\/p>\n<p>def add(a, b):<\/p>\n<p>    return a + b<\/p>\n<p>class TestAdd(unittest.TestCase):<\/p>\n<p>    def test_add(self):<\/p>\n<p>        self.assertEqual(add(3, 5), 8)<\/p>\n<p>        self.assertEqual(add(-1, 1), 0)<\/p>\n<p>if __name__ == &quot;__main__&quot;:<\/p>\n<p>    unittest.main()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u4f7f\u7528pytest\u8fdb\u884c\u5355\u5143\u6d4b\u8bd5<\/h4>\n<\/p>\n<p><p><code>pytest<\/code>\u662f\u4e00\u4e2a\u529f\u80fd\u5f3a\u5927\u7684\u6d4b\u8bd5\u6846\u67b6\u3002\u9996\u5148\uff0c\u901a\u8fc7<code>pip<\/code>\u5b89\u88c5<code>pytest<\/code>\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-sh\">pip install pytest<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\u7f16\u5199\u6d4b\u8bd5\u7528\u4f8b\u5e76\u8fd0\u884c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def add(a, b):<\/p>\n<p>    return a + b<\/p>\n<p>def test_add():<\/p>\n<p>    assert add(3, 5) == 8<\/p>\n<p>    assert add(-1, 1) == 0<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u547d\u4ee4\u884c\u4e2d\u8fd0\u884c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-sh\">pytest<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u5341\u56db\u3001\u4ee3\u7801\u4f18\u5316\u548c\u6027\u80fd\u8c03\u4f18<\/h3>\n<\/p>\n<p><h4>1\u3001\u4f7f\u7528profile\u8fdb\u884c\u6027\u80fd\u5206\u6790<\/h4>\n<\/p>\n<p><p>Python\u63d0\u4f9b\u4e86<code>cProfile<\/code>\u6a21\u5757\u7528\u4e8e\u6027\u80fd\u5206\u6790\u3002\u4f8b\u5982\uff0c\u5206\u6790\u4e00\u4e2a\u51fd\u6570\u7684\u6027\u80fd\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import cProfile<\/p>\n<p>def slow_function():<\/p>\n<p>    total = 0<\/p>\n<p>    for i in range(1000000):<\/p>\n<p>        total += i<\/p>\n<p>    return total<\/p>\n<p>cProfile.run(&#39;slow_function()&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u4f7f\u7528\u4f18\u5316\u5e93<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528NumPy\u7b49\u4f18\u5316\u5e93\u63d0\u9ad8\u6027\u80fd\u3002\u4f8b\u5982\uff0c\u4f7f\u7528NumPy\u8fdb\u884c\u77e9\u9635\u8fd0\u7b97\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>a = np.array([1, 2, 3])<\/p>\n<p>b = np.array([4, 5, 6])<\/p>\n<p>c = a + b<\/p>\n<p>print(c)  # \u8f93\u51fa: [5 7 9]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u5341\u4e94\u3001\u534f\u4f5c\u5f00\u53d1\u548c\u7248\u672c\u63a7\u5236<\/h3>\n<\/p>\n<p><h4>1\u3001\u4f7f\u7528Git\u8fdb\u884c\u7248\u672c\u63a7\u5236<\/h4>\n<\/p>\n<p><p>Git\u662f\u4e00\u4e2a\u5e38\u7528\u7684\u7248\u672c\u63a7\u5236\u7cfb\u7edf\u3002\u53ef\u4ee5\u901a\u8fc7Git\u7ba1\u7406\u4ee3\u7801\u7248\u672c\u3002\u4f8b\u5982\uff0c\u521d\u59cb\u5316\u4e00\u4e2aGit\u4ed3\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-sh\">git init<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6dfb\u52a0\u6587\u4ef6\u5e76\u63d0\u4ea4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-sh\">git add example.py<\/p>\n<p>git commit -m &quot;Initial commit&quot;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u4f7f\u7528GitHub\u8fdb\u884c\u534f\u4f5c\u5f00\u53d1<\/h4>\n<\/p>\n<p><p>GitHub\u662f\u4e00\u4e2a\u6d41\u884c\u7684\u4ee3\u7801\u6258\u7ba1\u5e73\u53f0\u3002\u53ef\u4ee5\u901a\u8fc7GitHub\u8fdb\u884c\u534f\u4f5c\u5f00\u53d1\u3002\u4f8b\u5982\uff0c\u521b\u5efa\u4e00\u4e2aGitHub\u4ed3\u5e93\u5e76\u63a8\u9001\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-sh\">git remote add origin https:\/\/github.com\/username\/repository.git<\/p>\n<p>git push -u origin master<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u5341\u516d\u3001Python\u7f16\u7a0b\u6280\u5de7<\/h3>\n<\/p>\n<p><h4>1\u3001\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f<\/h4>\n<\/p>\n<p><p>\u5217\u8868\u63a8\u5bfc\u5f0f\u53ef\u4ee5\u7b80\u5316\u5217\u8868\u7684\u521b\u5efa\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)  # \u8f93\u51fa: [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u7528Python\u7f16\u5199\u7b80\u5355\u7684\u7a0b\u5e8f\uff1f<\/strong><br \/>Python\u662f\u4e00\u79cd\u6613\u4e8e\u5b66\u4e60\u7684\u7f16\u7a0b\u8bed\u8a00\uff0c\u9002\u5408\u521d\u5b66\u8005\u3002\u8981\u7f16\u5199\u7b80\u5355\u7684\u7a0b\u5e8f\uff0c\u53ef\u4ee5\u9009\u62e9\u4e00\u4e2a\u6587\u672c\u7f16\u8f91\u5668\uff08\u5982VS Code\u6216PyCharm\uff09\uff0c\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Python\u6587\u4ef6\uff08.py\uff09\uff0c\u7136\u540e\u8f93\u5165\u4f60\u7684\u4ee3\u7801\u3002\u4f8b\u5982\uff0c\u6253\u5370\u201cHello, World!\u201d\u7684\u4ee3\u7801\u5982\u4e0b\uff1a  <\/p>\n<pre><code class=\"language-python\">print(&quot;Hello, World!&quot;)\n<\/code><\/pre>\n<p>\u4fdd\u5b58\u6587\u4ef6\u540e\uff0c\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165<code>python \u6587\u4ef6\u540d.py<\/code>\u6765\u8fd0\u884c\u7a0b\u5e8f\u3002\u719f\u6089\u57fa\u7840\u8bed\u6cd5\u540e\uff0c\u53ef\u4ee5\u5f00\u59cb\u63a2\u7d22\u53d8\u91cf\u3001\u6761\u4ef6\u8bed\u53e5\u548c\u5faa\u73af\u7b49\u6982\u5ff5\u3002<\/p>\n<p><strong>Python\u4e2d\u6709\u54ea\u4e9b\u5e38\u89c1\u7684\u5e93\u53ef\u4ee5\u4f7f\u7528\uff1f<\/strong><br \/>Python\u62e5\u6709\u4e30\u5bcc\u7684\u5e93\u548c\u6846\u67b6\uff0c\u53ef\u4ee5\u5e2e\u52a9\u4f60\u5b8c\u6210\u5404\u79cd\u4efb\u52a1\u3002\u5e38\u7528\u7684\u5e93\u5305\u62ec\uff1a  <\/p>\n<ul>\n<li><strong>NumPy<\/strong>\uff1a\u7528\u4e8e\u79d1\u5b66\u8ba1\u7b97\uff0c\u63d0\u4f9b\u652f\u6301\u5927\u578b\u3001\u591a\u7ef4\u6570\u7ec4\u548c\u77e9\u9635\u7684\u5de5\u5177\u3002  <\/li>\n<li><strong>Pandas<\/strong>\uff1a\u5f3a\u5927\u7684\u6570\u636e\u5206\u6790\u548c\u64cd\u4f5c\u5e93\uff0c\u9002\u5408\u5904\u7406\u7ed3\u6784\u5316\u6570\u636e\u3002  <\/li>\n<li><strong>Requests<\/strong>\uff1a\u7528\u4e8e\u53d1\u9001HTTP\u8bf7\u6c42\uff0c\u9002\u5408\u8fdb\u884c\u7f51\u7edc\u722c\u866b\u548cAPI\u4ea4\u4e92\u3002  <\/li>\n<li><strong>Flask<\/strong>\u548c<strong>Django<\/strong>\uff1a\u7528\u4e8e\u5f00\u53d1Web\u5e94\u7528\u7684\u6d41\u884c\u6846\u67b6\u3002<br \/>\u8fd9\u4e9b\u5e93\u53ef\u4ee5\u6781\u5927\u5730\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u548c\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u3002<\/li>\n<\/ul>\n<p><strong>\u5982\u4f55\u8c03\u8bd5Python\u4ee3\u7801\u4ee5\u89e3\u51b3\u9519\u8bef\uff1f<\/strong><br \/>\u8c03\u8bd5\u662f\u7f16\u7a0b\u8fc7\u7a0b\u4e2d\u4e0d\u53ef\u6216\u7f3a\u7684\u4e00\u90e8\u5206\u3002Python\u63d0\u4f9b\u4e86\u4e00\u4e9b\u8c03\u8bd5\u5de5\u5177\u548c\u6280\u5de7\u6765\u5e2e\u52a9\u5f00\u53d1\u8005\u8bc6\u522b\u548c\u4fee\u590d\u4ee3\u7801\u4e2d\u7684\u9519\u8bef\u3002\u53ef\u4ee5\u4f7f\u7528\u5185\u7f6e\u7684<code>print()<\/code>\u51fd\u6570\u6765\u8f93\u51fa\u53d8\u91cf\u7684\u503c\uff0c\u5e2e\u52a9\u7406\u89e3\u7a0b\u5e8f\u7684\u6267\u884c\u8fc7\u7a0b\u3002\u6b64\u5916\uff0cPython\u7684<code>pdb<\/code>\u6a21\u5757\u63d0\u4f9b\u4e86\u4ea4\u4e92\u5f0f\u8c03\u8bd5\u529f\u80fd\uff0c\u5141\u8bb8\u9010\u884c\u6267\u884c\u4ee3\u7801\uff0c\u68c0\u67e5\u53d8\u91cf\u503c\u5e76\u8bbe\u7f6e\u65ad\u70b9\u3002\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u901a\u5e38\u4e5f\u63d0\u4f9b\u56fe\u5f62\u5316\u7684\u8c03\u8bd5\u5de5\u5177\uff0c\u8ba9\u8c03\u8bd5\u8fc7\u7a0b\u66f4\u52a0\u76f4\u89c2\u548c\u9ad8\u6548\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u662f\u4e00\u79cd\u9ad8\u7ea7\u7f16\u7a0b\u8bed\u8a00\uff0c\u5e7f\u6cdb\u7528\u4e8eWeb\u5f00\u53d1\u3001\u6570\u636e\u5206\u6790\u3001\u4eba\u5de5\u667a\u80fd\u548c\u81ea\u52a8\u5316\u4efb\u52a1\u7b49\u9886\u57df\u3002Python\u53ef\u4ee5\u901a\u8fc7 [&hellip;]","protected":false},"author":3,"featured_media":1147976,"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\/1147971"}],"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=1147971"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1147971\/revisions"}],"predecessor-version":[{"id":1147977,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1147971\/revisions\/1147977"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1147976"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1147971"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1147971"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1147971"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}