{"id":936946,"date":"2024-12-26T19:40:14","date_gmt":"2024-12-26T11:40:14","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/936946.html"},"modified":"2024-12-26T19:40:17","modified_gmt":"2024-12-26T11:40:17","slug":"python%e4%b8%ad%e5%a6%82%e4%bd%95%e5%ae%9a%e4%b9%89","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/936946.html","title":{"rendered":"python\u4e2d\u5982\u4f55\u5b9a\u4e49"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25073011\/2f01e8d4-4883-4b80-b6d4-0e9dc94d196f.webp\" alt=\"python\u4e2d\u5982\u4f55\u5b9a\u4e49\" \/><\/p>\n<p><p> \u5728Python\u4e2d\u5b9a\u4e49\u53d8\u91cf\u3001\u51fd\u6570\u548c\u7c7b\u7684\u65b9\u5f0f\u5404\u6709\u4e0d\u540c\u3002<strong>\u5b9a\u4e49\u53d8\u91cf\u65f6\uff0c\u65e0\u9700\u58f0\u660e\u6570\u636e\u7c7b\u578b\uff0c\u76f4\u63a5\u8d4b\u503c\u5373\u53ef\uff1b\u5b9a\u4e49\u51fd\u6570\u4f7f\u7528<code>def<\/code>\u5173\u952e\u5b57\uff0c\u540e\u8ddf\u51fd\u6570\u540d\u548c\u53c2\u6570\u5217\u8868\uff1b\u5b9a\u4e49\u7c7b\u5219\u4f7f\u7528<code>class<\/code>\u5173\u952e\u5b57\uff0c\u540e\u8ddf\u7c7b\u540d\u548c\u5192\u53f7\u3002<\/strong>\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u6bcf\u79cd\u5b9a\u4e49\u65b9\u5f0f\uff0c\u5e76\u63a2\u8ba8\u5b83\u4eec\u7684\u4f7f\u7528\u573a\u666f\u548c\u6ce8\u610f\u4e8b\u9879\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u53d8\u91cf\u7684\u5b9a\u4e49<\/h3>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u53d8\u91cf\u7684\u5b9a\u4e49\u662f\u52a8\u6001\u7684\uff0c\u8fd9\u610f\u5473\u7740\u4f60\u4e0d\u9700\u8981\u63d0\u524d\u6307\u5b9a\u53d8\u91cf\u7684\u6570\u636e\u7c7b\u578b\u3002Python\u89e3\u91ca\u5668\u4f1a\u6839\u636e\u4f60\u8d4b\u7ed9\u53d8\u91cf\u7684\u503c\u81ea\u52a8\u63a8\u65ad\u5176\u7c7b\u578b\u3002\u5b9a\u4e49\u53d8\u91cf\u7684\u57fa\u672c\u683c\u5f0f\u662f\uff1a<code>\u53d8\u91cf\u540d = \u503c<\/code>\u3002<\/p>\n<\/p>\n<p><h4>1.1 \u52a8\u6001\u7c7b\u578b<\/h4>\n<\/p>\n<p><p>Python\u7684\u53d8\u91cf\u662f\u52a8\u6001\u7c7b\u578b\u7684\uff0c\u8fd9\u610f\u5473\u7740\u540c\u4e00\u4e2a\u53d8\u91cf\u53ef\u4ee5\u5728\u4e0d\u540c\u65f6\u5019\u5b58\u50a8\u4e0d\u540c\u7c7b\u578b\u7684\u6570\u636e\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">x = 10        # x \u662f\u4e00\u4e2a\u6574\u6570<\/p>\n<p>x = &quot;Hello&quot;   # \u73b0\u5728 x \u662f\u4e00\u4e2a\u5b57\u7b26\u4e32<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u7075\u6d3b\u6027\u4f7f\u5f97Python\u975e\u5e38\u9002\u5408\u5feb\u901f\u5f00\u53d1\u548c\u539f\u578b\u8bbe\u8ba1\uff0c\u4f46\u4e5f\u8981\u6c42\u5f00\u53d1\u8005\u5728\u4f7f\u7528\u53d8\u91cf\u65f6\u5c0f\u5fc3\uff0c\u4ee5\u907f\u514d\u7c7b\u578b\u4e0d\u4e00\u81f4\u7684\u95ee\u9898\u3002<\/p>\n<\/p>\n<p><h4>1.2 \u547d\u540d\u89c4\u5219<\/h4>\n<\/p>\n<p><p>Python\u53d8\u91cf\u547d\u540d\u9700\u8981\u9075\u5faa\u4e00\u5b9a\u7684\u89c4\u5219\u548c\u60ef\u4f8b\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u53d8\u91cf\u540d\u5fc5\u987b\u4ee5\u5b57\u6bcd\uff08a-z, A-Z\uff09\u6216\u4e0b\u5212\u7ebf\uff08_\uff09\u5f00\u5934\uff0c\u4e0d\u80fd\u4ee5\u6570\u5b57\u5f00\u5934\u3002<\/li>\n<li>\u53d8\u91cf\u540d\u53ea\u80fd\u5305\u542b\u5b57\u6bcd\u3001\u6570\u5b57\u548c\u4e0b\u5212\u7ebf\u3002<\/li>\n<li>Python\u5bf9\u5927\u5c0f\u5199\u654f\u611f\uff0c\u56e0\u6b64<code>myvar<\/code>\u548c<code>MyVar<\/code>\u662f\u4e24\u4e2a\u4e0d\u540c\u7684\u53d8\u91cf\u3002<\/li>\n<li>\u907f\u514d\u4f7f\u7528Python\u7684\u4fdd\u7559\u5b57\u4f5c\u4e3a\u53d8\u91cf\u540d\uff0c\u5982<code>if<\/code>\u3001<code>for<\/code>\u3001<code>while<\/code>\u7b49\u3002<\/li>\n<\/ul>\n<p><p>\u826f\u597d\u7684\u53d8\u91cf\u547d\u540d\u4e60\u60ef\u6709\u52a9\u4e8e\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u548c\u53ef\u7ef4\u62a4\u6027\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u51fd\u6570\u7684\u5b9a\u4e49<\/h3>\n<\/p>\n<p><p>\u51fd\u6570\u662fPython\u4e2d\u7684\u4e00\u7b49\u516c\u6c11\uff0c\u7528\u4e8e\u5c01\u88c5\u4e00\u6bb5\u4ee3\u7801\u4ee5\u4fbf\u91cd\u7528\u3002Python\u4f7f\u7528<code>def<\/code>\u5173\u952e\u5b57\u5b9a\u4e49\u51fd\u6570\uff0c\u540e\u8ddf\u51fd\u6570\u540d\u3001\u53c2\u6570\u5217\u8868\u548c\u5192\u53f7\u3002<\/p>\n<\/p>\n<p><h4>2.1 \u57fa\u672c\u683c\u5f0f<\/h4>\n<\/p>\n<p><p>\u5b9a\u4e49\u51fd\u6570\u7684\u57fa\u672c\u683c\u5f0f\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def \u51fd\u6570\u540d(\u53c2\u65701, \u53c2\u65702, ...):<\/p>\n<p>    &quot;&quot;&quot;\u6587\u6863\u5b57\u7b26\u4e32\uff08\u53ef\u9009\uff09&quot;&quot;&quot;<\/p>\n<p>    \u51fd\u6570\u4f53<\/p>\n<p>    return \u8fd4\u56de\u503c\uff08\u53ef\u9009\uff09<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4f8b\u5982\uff0c\u5b9a\u4e49\u4e00\u4e2a\u7b80\u5355\u7684\u52a0\u6cd5\u51fd\u6570\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def add(a, b):<\/p>\n<p>    return a + b<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2.2 \u53c2\u6570\u548c\u8fd4\u56de\u503c<\/h4>\n<\/p>\n<p><p>Python\u51fd\u6570\u652f\u6301\u591a\u79cd\u53c2\u6570\u4f20\u9012\u65b9\u5f0f\uff0c\u5305\u62ec\u4f4d\u7f6e\u53c2\u6570\u3001\u9ed8\u8ba4\u53c2\u6570\u3001\u5173\u952e\u5b57\u53c2\u6570\u548c\u53ef\u53d8\u53c2\u6570\u3002\u8fd9\u4e9b\u7279\u6027\u4f7f\u5f97Python\u51fd\u6570\u975e\u5e38\u7075\u6d3b\u3002<\/p>\n<\/p>\n<ul>\n<li><strong>\u4f4d\u7f6e\u53c2\u6570<\/strong>\uff1a\u6700\u5e38\u89c1\u7684\u53c2\u6570\u4f20\u9012\u65b9\u5f0f\uff0c\u6309\u4f4d\u7f6e\u987a\u5e8f\u4f20\u9012\u3002<\/li>\n<li><strong>\u9ed8\u8ba4\u53c2\u6570<\/strong>\uff1a\u53ef\u4ee5\u4e3a\u51fd\u6570\u53c2\u6570\u8bbe\u7f6e\u9ed8\u8ba4\u503c\uff0c\u8c03\u7528\u65f6\u53ef\u4ee5\u4e0d\u4f20\u9012\u8be5\u53c2\u6570\u3002<\/li>\n<li><strong>\u5173\u952e\u5b57\u53c2\u6570<\/strong>\uff1a\u8c03\u7528\u51fd\u6570\u65f6\u53ef\u4ee5\u663e\u5f0f\u6307\u5b9a\u53c2\u6570\u540d\uff0c\u4ece\u800c\u6253\u7834\u4f4d\u7f6e\u987a\u5e8f\u3002<\/li>\n<li><strong>\u53ef\u53d8\u53c2\u6570<\/strong>\uff1a\u4f7f\u7528<code>*args<\/code>\u548c<code>kwargs<\/code>\u63a5\u6536\u4efb\u610f\u6570\u91cf\u7684\u4f4d\u7f6e\u53c2\u6570\u548c\u5173\u952e\u5b57\u53c2\u6570\u3002<\/li>\n<\/ul>\n<p><p>\u8fd4\u56de\u503c\u662f\u53ef\u9009\u7684\uff0c\u51fd\u6570\u53ef\u4ee5\u8fd4\u56de\u4e00\u4e2a\u503c\u3001\u591a\u4e2a\u503c\uff08\u4ee5\u5143\u7ec4\u5f62\u5f0f\uff09\u6216\u8005\u4e0d\u8fd4\u56de\u503c\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u7c7b\u7684\u5b9a\u4e49<\/h3>\n<\/p>\n<p><p>Python\u662f\u4e00\u79cd\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\u8bed\u8a00\uff0c\u7c7b\u662f\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\u7684\u6838\u5fc3\u6982\u5ff5\u3002\u4f7f\u7528<code>class<\/code>\u5173\u952e\u5b57\u5b9a\u4e49\u7c7b\u3002<\/p>\n<\/p>\n<p><h4>3.1 \u57fa\u672c\u683c\u5f0f<\/h4>\n<\/p>\n<p><p>\u5b9a\u4e49\u7c7b\u7684\u57fa\u672c\u683c\u5f0f\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">class \u7c7b\u540d:<\/p>\n<p>    &quot;&quot;&quot;\u6587\u6863\u5b57\u7b26\u4e32\uff08\u53ef\u9009\uff09&quot;&quot;&quot;<\/p>\n<p>    def __init__(self, \u53c2\u65701, \u53c2\u65702, ...):<\/p>\n<p>        &quot;&quot;&quot;\u521d\u59cb\u5316\u65b9\u6cd5&quot;&quot;&quot;<\/p>\n<p>        self.\u5c5e\u60271 = \u53c2\u65701<\/p>\n<p>        self.\u5c5e\u60272 = \u53c2\u65702<\/p>\n<p>    def \u65b9\u6cd51(self):<\/p>\n<p>        &quot;&quot;&quot;\u7c7b\u65b9\u6cd5&quot;&quot;&quot;<\/p>\n<p>        pass<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4f8b\u5982\uff0c\u5b9a\u4e49\u4e00\u4e2a\u7b80\u5355\u7684<code>Person<\/code>\u7c7b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">class Person:<\/p>\n<p>    def __init__(self, name, age):<\/p>\n<p>        self.name = name<\/p>\n<p>        self.age = age<\/p>\n<p>    def greet(self):<\/p>\n<p>        print(f&quot;Hello, my name is {self.name} and I am {self.age} years old.&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3.2 \u7ee7\u627f\u548c\u591a\u6001<\/h4>\n<\/p>\n<p><p>Python\u652f\u6301\u7c7b\u7684\u7ee7\u627f\uff0c\u4e00\u4e2a\u7c7b\u53ef\u4ee5\u4ece\u53e6\u4e00\u4e2a\u7c7b\u7ee7\u627f\u5c5e\u6027\u548c\u65b9\u6cd5\u3002\u8fd9\u4f7f\u5f97\u4ee3\u7801\u66f4\u52a0\u53ef\u91cd\u7528\u548c\u53ef\u6269\u5c55\u3002\u591a\u6001\u662f\u6307\u4e0d\u540c\u7684\u5bf9\u8c61\u53ef\u4ee5\u901a\u8fc7\u76f8\u540c\u7684\u63a5\u53e3\u8c03\u7528\u65b9\u6cd5\u800c\u8868\u73b0\u51fa\u4e0d\u540c\u7684\u884c\u4e3a\u3002<\/p>\n<\/p>\n<p><p>\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">class Student(Person):<\/p>\n<p>    def __init__(self, name, age, student_id):<\/p>\n<p>        super().__init__(name, age)<\/p>\n<p>        self.student_id = student_id<\/p>\n<p>    def greet(self):<\/p>\n<p>        print(f&quot;Hello, I am {self.name}, a student with ID {self.student_id}.&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c<code>Student<\/code>\u7c7b\u7ee7\u627f\u4e86<code>Person<\/code>\u7c7b\uff0c\u5e76\u91cd\u5199\u4e86<code>greet<\/code>\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u6a21\u5757\u548c\u5305<\/h3>\n<\/p>\n<p><p>Python\u4e2d\u7684\u6a21\u5757\u548c\u5305\u662f\u7ec4\u7ec7\u548c\u7ba1\u7406\u4ee3\u7801\u7684\u57fa\u672c\u5355\u4f4d\u3002\u6a21\u5757\u662f\u4e00\u4e2a\u5305\u542bPython\u4ee3\u7801\u7684\u6587\u4ef6\uff0c\u800c\u5305\u662f\u4e00\u4e2a\u5305\u542b\u591a\u4e2a\u6a21\u5757\u7684\u76ee\u5f55\u3002<\/p>\n<\/p>\n<p><h4>4.1 \u6a21\u5757\u7684\u5b9a\u4e49<\/h4>\n<\/p>\n<p><p>\u4efb\u4f55Python\u6587\u4ef6\u90fd\u53ef\u4ee5\u4f5c\u4e3a\u4e00\u4e2a\u6a21\u5757\u4f7f\u7528\u3002\u901a\u8fc7<code>import<\/code>\u8bed\u53e5\u53ef\u4ee5\u5728\u5176\u4ed6\u6587\u4ef6\u4e2d\u5bfc\u5165\u8be5\u6a21\u5757\u3002\u4f8b\u5982\uff0c\u5047\u8bbe\u6709\u4e00\u4e2a<code>math_utils.py<\/code>\u6587\u4ef6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># math_utils.py<\/p>\n<p>def add(a, b):<\/p>\n<p>    return a + b<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u53ef\u4ee5\u5728\u53e6\u4e00\u4e2a\u6587\u4ef6\u4e2d\u5bfc\u5165\u5e76\u4f7f\u7528\u8be5\u6a21\u5757\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import math_utils<\/p>\n<p>result = math_utils.add(5, 3)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>4.2 \u5305\u7684\u5b9a\u4e49<\/h4>\n<\/p>\n<p><p>\u5305\u662f\u4e00\u79cd\u7ec4\u7ec7\u591a\u4e2a\u6a21\u5757\u7684\u65b9\u5f0f\u3002\u5305\u662f\u4e00\u4e2a\u76ee\u5f55\uff0c\u76ee\u5f55\u4e0b\u5fc5\u987b\u5305\u542b\u4e00\u4e2a<code>__init__.py<\/code>\u6587\u4ef6\uff0c\u8fd9\u4e2a\u6587\u4ef6\u53ef\u4ee5\u662f\u7a7a\u7684\uff0c\u4f46\u5176\u5b58\u5728\u8868\u660e\u8be5\u76ee\u5f55\u662f\u4e00\u4e2a\u5305\u3002<\/p>\n<\/p>\n<p><p>\u4f8b\u5982\uff0c\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a<code>utilities<\/code>\u7684\u5305\uff1a<\/p>\n<\/p>\n<p><pre><code>utilities\/<\/p>\n<p>    __init__.py<\/p>\n<p>    math_utils.py<\/p>\n<p>    string_utils.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u53ef\u4ee5\u5728\u5176\u4ed6\u6587\u4ef6\u4e2d\u4f7f\u7528\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from utilities import math_utils<\/p>\n<p>result = math_utils.add(5, 3)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e94\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>Python\u4e2d\u5b9a\u4e49\u53d8\u91cf\u3001\u51fd\u6570\u3001\u7c7b\u3001\u6a21\u5757\u548c\u5305\u7684\u65b9\u6cd5\u5404\u6709\u4e0d\u540c\uff0c\u4f46\u90fd\u662fPython\u8bed\u8a00\u7075\u6d3b\u6027\u548c\u5f3a\u5927\u529f\u80fd\u7684\u4f53\u73b0\u3002<strong>\u7406\u89e3\u8fd9\u4e9b\u57fa\u672c\u6982\u5ff5\u548c\u7528\u6cd5\u662f\u638c\u63e1Python\u7f16\u7a0b\u7684\u57fa\u7840<\/strong>\u3002\u901a\u8fc7\u5408\u7406\u5730\u4f7f\u7528\u8fd9\u4e9b\u7279\u6027\uff0c\u53ef\u4ee5\u7f16\u5199\u51fa\u7ed3\u6784\u6e05\u6670\u3001\u6613\u4e8e\u7ef4\u62a4\u7684\u4ee3\u7801\u3002\u968f\u7740\u5bf9Python\u7684\u6df1\u5165\u5b66\u4e60\uff0c\u53ef\u4ee5\u63a2\u7d22\u66f4\u591a\u9ad8\u7ea7\u7279\u6027\uff0c\u5982\u88c5\u9970\u5668\u3001\u751f\u6210\u5668\u548c\u4e0a\u4e0b\u6587\u7ba1\u7406\u5668\u7b49\uff0c\u4ee5\u8fdb\u4e00\u6b65\u63d0\u5347\u4ee3\u7801\u8d28\u91cf\u548c\u5f00\u53d1\u6548\u7387\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5728Python\u4e2d\u5982\u4f55\u5b9a\u4e49\u4e00\u4e2a\u51fd\u6570\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u5b9a\u4e49\u4e00\u4e2a\u51fd\u6570\u4f7f\u7528<code>def<\/code>\u5173\u952e\u5b57\uff0c\u540e\u9762\u8ddf\u4e0a\u51fd\u6570\u540d\u548c\u53c2\u6570\u5217\u8868\u3002\u51fd\u6570\u4f53\u5fc5\u987b\u7f29\u8fdb\uff0c\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-python\">def my_function(param1, param2):\n    return param1 + param2\n<\/code><\/pre>\n<p>\u8fd9\u6837\u5c31\u5b9a\u4e49\u4e86\u4e00\u4e2a\u540d\u4e3a<code>my_function<\/code>\u7684\u51fd\u6570\uff0c\u5b83\u63a5\u53d7\u4e24\u4e2a\u53c2\u6570\u5e76\u8fd4\u56de\u5b83\u4eec\u7684\u548c\u3002<\/p>\n<p><strong>Python\u652f\u6301\u54ea\u4e9b\u7c7b\u578b\u7684\u53d8\u91cf\u5b9a\u4e49\uff1f<\/strong><br \/>Python\u652f\u6301\u591a\u79cd\u7c7b\u578b\u7684\u53d8\u91cf\u5b9a\u4e49\uff0c\u5305\u62ec\u6574\u6570\u3001\u6d6e\u70b9\u6570\u3001\u5b57\u7b26\u4e32\u548c\u5217\u8868\u7b49\u3002\u53ef\u4ee5\u901a\u8fc7\u76f4\u63a5\u8d4b\u503c\u6765\u5b9a\u4e49\u53d8\u91cf\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre><code class=\"language-python\">x = 10          # \u6574\u6570\ny = 3.14        # \u6d6e\u70b9\u6570\nname = &quot;Alice&quot;  # \u5b57\u7b26\u4e32\nnumbers = [1, 2, 3]  # \u5217\u8868\n<\/code><\/pre>\n<p>\u8fd9\u4e9b\u53d8\u91cf\u53ef\u4ee5\u6839\u636e\u9700\u8981\u968f\u65f6\u66f4\u6539\u5176\u503c\u548c\u7c7b\u578b\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u5982\u4f55\u5b9a\u4e49\u7c7b\uff1f<\/strong><br \/>\u5b9a\u4e49\u7c7b\u4f7f\u7528<code>class<\/code>\u5173\u952e\u5b57\uff0c\u540e\u9762\u8ddf\u4e0a\u7c7b\u540d\u548c\u53ef\u9009\u7684\u7236\u7c7b\u3002\u7c7b\u4f53\u540c\u6837\u9700\u8981\u7f29\u8fdb\uff0c\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-python\">class MyClass:\n    def __init__(self, value):\n        self.value = value\n\n    def display(self):\n        print(self.value)\n<\/code><\/pre>\n<p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c<code>MyClass<\/code>\u5b9a\u4e49\u4e86\u4e00\u4e2a\u521d\u59cb\u5316\u65b9\u6cd5\u548c\u4e00\u4e2a\u663e\u793a\u65b9\u6cd5\uff0c\u53ef\u4ee5\u7528\u4e8e\u521b\u5efa\u5bf9\u8c61\u5e76\u64cd\u4f5c\u5176\u5c5e\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u5b9a\u4e49\u53d8\u91cf\u3001\u51fd\u6570\u548c\u7c7b\u7684\u65b9\u5f0f\u5404\u6709\u4e0d\u540c\u3002\u5b9a\u4e49\u53d8\u91cf\u65f6\uff0c\u65e0\u9700\u58f0\u660e\u6570\u636e\u7c7b\u578b\uff0c\u76f4\u63a5\u8d4b\u503c\u5373\u53ef\uff1b\u5b9a\u4e49\u51fd\u6570\u4f7f\u7528de [&hellip;]","protected":false},"author":3,"featured_media":936947,"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\/936946"}],"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=936946"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/936946\/revisions"}],"predecessor-version":[{"id":936948,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/936946\/revisions\/936948"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/936947"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=936946"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=936946"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=936946"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}