{"id":41720,"date":"2023-12-11T14:54:23","date_gmt":"2023-12-11T06:54:23","guid":{"rendered":"https:\/\/wx.kaifamiao.info\/?p=41720"},"modified":"2023-12-11T14:54:23","modified_gmt":"2023-12-11T06:54:23","slug":"python%e9%9d%a2%e5%90%91%e5%af%b9%e8%b1%a1%e4%b8%ad%e7%9a%84%e7%bb%a7%e6%89%bf%e6%9c%89%e4%bb%80%e4%b9%88%e7%89%b9%e7%82%b9","status":"publish","type":"post","link":"http:\/\/wx.kaifamiao.info\/index.php\/2023\/12\/11\/python%e9%9d%a2%e5%90%91%e5%af%b9%e8%b1%a1%e4%b8%ad%e7%9a%84%e7%bb%a7%e6%89%bf%e6%9c%89%e4%bb%80%e4%b9%88%e7%89%b9%e7%82%b9\/","title":{"rendered":"Python\u9762\u5411\u5bf9\u8c61\u4e2d\u7684\u7ee7\u627f\u6709\u4ec0\u4e48\u7279\u70b9"},"content":{"rendered":"<p>&#8220;`&#8221;<\/p>\n<p>&lt;pre&gt;&lt;code&gt;\u7ee7\u627f\u6982\u5ff5\u7684\u5b9e\u73b0\u65b9\u5f0f\u4e3b\u8981\u67092\u7c7b\uff1a\u5b9e\u73b0\u7ee7\u627f\u3001\u63a5\u53e3\u7ee7\u627f\u3002<\/p>\n<p>         \u5b9e\u73b0\u7ee7\u627f\u662f\u6307\u4f7f\u7528\u57fa\u7c7b\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\u800c\u65e0\u9700\u989d\u5916\u7f16\u7801\u7684\u80fd\u529b\uff1b<br \/>\n         \u63a5\u53e3\u7ee7\u627f\u662f\u6307\u4ec5\u4f7f\u7528\u5c5e\u6027\u548c\u65b9\u6cd5\u7684\u540d\u79f0\u3001\u4f46\u662f\u5b50\u7c7b\u5fc5\u987b\u63d0\u4f9b\u5b9e\u73b0\u7684\u80fd\u529b(\u5b50\u7c7b\u91cd\u6784\u7239\u7c7b\u65b9\u6cd5)\uff1b<br \/>\npython \u4e24\u79cd\u7c7b\uff1a\u7ecf\u5178\u7c7b \u65b0\u5f0f\u7c7b<br \/>\npython3 \u65b0\u5f0f\u7c7b \u2014\u2014 \u90fd\u9ed8\u8ba4\u7ee7\u627fobject class Animal(object): == class Animal:<br \/>\npython2 \u7ecf\u5178\u7c7b\u548c\u65b0\u5f0f\u7c7b \u5e76\u5b58<br \/>\n        class Animal:  \u7ecf\u5178\u7c7b \u2014\u2014 \u7ee7\u627f\u987a\u5e8f \u4e2a\u522b\u4f7f\u7528\u65b9\u6cd5<br \/>\n        class Animal(object):  \u65b0\u5f0f\u7c7b<\/p>\n<p>\u7ee7\u627f\u5206\u4e3a\u5355\u7ee7\u627f\u548c\u591a\u7ee7\u627f<br \/>\nPython\u662f\u652f\u6301\u591a\u7ee7\u627f\u7684<br \/>\n\u5982\u679c\u6ca1\u6709\u6307\u5b9a\u57fa\u7c7b\uff0cpython\u7684\u7c7b\u4f1a\u9ed8\u8ba4\u7ee7\u627fobject\u7c7b\uff0cobject\u662f\u6240\u6709python\u7c7b\u7684\u57fa\u7c7b\uff0c\u5b83\u63d0\u4f9b\u4e86\u4e00\u4e9b\u5e38\u89c1\u65b9\u6cd5\uff08\u5982__str__\uff09\u7684\u5b9e\u73b0\u3002<br \/>\n&lt;\/code&gt;&lt;\/pre&gt;<\/p>\n<p>\u00a0<\/p>\n<p>\u00a0<\/p>\n<p>\u8865\u5145\u7ee7\u627f\u7684\u5e94\u7528\uff08\u9762\u8bd5\u9898\uff09<\/p>\n<p>\u00a0<\/p>\n<p>\u00a0<\/p>\n<p>&lt;pre&gt;&lt;code&gt;1\u3001\u5bf9\u8c61\u53ef\u4ee5\u8c03\u7528\u81ea\u5df1\u672c\u7c7b\u548c\u7236\u7c7b\u7684\u6240\u6709\u65b9\u6cd5\u548c\u5c5e\u6027\uff0c \u5148\u8c03\u7528\u81ea\u5df1\u7684 \u81ea\u5df1\u6ca1\u6709\u624d\u8c03\u7236\u7c7b\u7684\u3002\u8c01\uff08\u5bf9\u8c61\uff09\u8c03\u7528\u65b9\u6cd5\uff0c\u65b9\u6cd5\u4e2d\u7684self\u5c31\u6307\u5411\u8c01<\/p>\n<p>class Foo:<br \/>\n    def __init__(self):<br \/>\n        self.func()<\/p>\n<p>    def func(self):<br \/>\n        print(&#039;Foo.func&#039;)<\/p>\n<p>class Son(Foo):<br \/>\n    def func(self):<br \/>\n        print(&#039;Son.func&#039;)<\/p>\n<p>s = Son()<br \/>\n # Son.func<\/p>\n<p>========================================================<br \/>\nclass A:<br \/>\n    def get(self):<br \/>\n        self.say()<\/p>\n<p>    def say(self):<br \/>\n        print(&#039;AAAAA&#039;)<\/p>\n<p>class B(A):<br \/>\n    def say(self):<br \/>\n        print(&#039;BBBBB&#039;)<\/p>\n<p>b = B()<br \/>\nb.get()   #\u8f93\u51fa\u7ed3\u679c\u4e3a\uff1aBBBBB<br \/>\n&lt;\/code&gt;&lt;\/pre&gt;<\/p>\n<p>\u00a0<\/p>\n<p>\u00a0<\/p>\n<p>\u00a0<\/p>\n<p>&lt;pre&gt;&lt;code&gt;            &quot;&#8220;`<br \/>\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;`&#8221; &lt;pre&gt;&lt;code&gt;\u7ee7\u627f\u6982\u5ff5\u7684\u5b9e\u73b0\u65b9\u5f0f\u4e3b\u8981\u67092\u7c7b\uff1a\u5b9e [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-41720","post","type-post","status-publish","format-standard","hentry","category-c"],"_links":{"self":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/41720","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/comments?post=41720"}],"version-history":[{"count":1,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/41720\/revisions"}],"predecessor-version":[{"id":41721,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/41720\/revisions\/41721"}],"wp:attachment":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/media?parent=41720"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/categories?post=41720"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/tags?post=41720"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}