{"id":192,"date":"2023-02-22T22:08:54","date_gmt":"2023-02-22T14:08:54","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=192"},"modified":"2023-02-22T22:10:14","modified_gmt":"2023-02-22T14:10:14","slug":"python-class-variable-member-variable-static-method-member-method","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/22\/python-class-variable-member-variable-static-method-member-method\/","title":{"rendered":"Python\u4e2d\u7684\u7c7b\u53d8\u91cf\u3001\u6210\u5458\u53d8\u91cf\u3001\u9759\u6001\u65b9\u6cd5\u3001\u6210\u5458\u65b9\u6cd5"},"content":{"rendered":"<p>Python \u7684\u7c7b\u4e2d\uff0c\u4e3b\u8981\u4f1a\u4f7f\u7528\u7684\u4e24\u79cd\u53d8\u91cf\uff1a\u7c7b\u53d8\u91cf\u4e0e\u6210\u5458\u53d8\u91cf\u3002\u7c7b\u53d8\u91cf\u662f\u7c7b\u6240\u6709\u5b9e\u4f8b\u5316\u5bf9\u8c61\u5171\u6709\u7684\uff0c\u800c\u6210\u5458\u53d8\u91cf\u662f\u6bcf\u4e2a\u5b9e\u4f8b\u5316\u5bf9\u8c61\u81ea\u8eab\u7279\u6709\u7684\u3002<\/p>\n<p><!-- more --><\/p>\n<pre><code class=\"language-python\"># -*- coding: utf-8 -*-\n\nclass ClassTest():\n    static_a = &#039;AppBlog.CN&#039;\n\n    def __init__(self):\n        self.a = &#039;Hello World&#039;\n        pass\n\n    def method(self):\n        print &#039;\u6210\u5458\u65b9\u6cd5: method&#039;\n\n    @staticmethod\n    def static_method():\n        print &#039;\u9759\u6001\u65b9\u6cd5: static_method&#039;\n\nif __name__==&#039;__main__&#039;:\n    print &#039;---------- \u901a\u8fc7\u7c7b\u8c03\u7528 ----------&#039;\n    print &#039;\u7c7b\u53d8\u91cf: &#039; + ClassTest.static_a\n    ClassTest.static_method()\n\n    print &#039;---------- \u901a\u8fc7\u5bf9\u8c61\u8c03\u7528 ----------&#039;\n    test = ClassTest()\n    print &#039;\u7c7b\u53d8\u91cf: &#039; + test.static_a\n    print &#039;\u6210\u5458\u53d8\u91cf: &#039; + test.a\n    test.static_method()\n    test.method()<\/code><\/pre>\n<p>\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n<pre><code>---------- \u901a\u8fc7\u7c7b\u8c03\u7528 ----------\n\u7c7b\u53d8\u91cf: AppBlog.CN\n\u9759\u6001\u65b9\u6cd5: static_method\n---------- \u901a\u8fc7\u5bf9\u8c61\u8c03\u7528 ----------\n\u7c7b\u53d8\u91cf: AppBlog.CN\n\u6210\u5458\u53d8\u91cf: Hello World\n\u9759\u6001\u65b9\u6cd5: static_method\n\u6210\u5458\u65b9\u6cd5: method<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Python \u7684\u7c7b\u4e2d\uff0c\u4e3b\u8981\u4f1a\u4f7f\u7528\u7684\u4e24\u79cd\u53d8\u91cf\uff1a\u7c7b\u53d8\u91cf\u4e0e\u6210\u5458\u53d8\u91cf\u3002\u7c7b\u53d8\u91cf\u662f\u7c7b\u6240\u6709\u5b9e\u4f8b\u5316\u5bf9\u8c61\u5171\u6709\u7684\uff0c\u800c\u6210\u5458\u53d8\u91cf\u662f\u6bcf\u4e2a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[79],"tags":[],"class_list":["post-192","post","type-post","status-publish","format-standard","hentry","category-python"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/192","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=192"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/192\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=192"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=192"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=192"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}