{"id":867,"date":"2024-11-07T12:05:43","date_gmt":"2024-11-07T04:05:43","guid":{"rendered":"https:\/\/fwq.ai\/blog\/867\/"},"modified":"2024-11-07T12:05:43","modified_gmt":"2024-11-07T04:05:43","slug":"python-%e7%b1%bb%e4%b8%ad%e6%96%b9%e6%b3%95%e5%a6%82%e4%bd%95%e4%bf%ae%e6%94%b9%e5%b1%9e%e6%80%a7%e5%80%bc%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/867\/","title":{"rendered":"Python \u7c7b\u4e2d\u65b9\u6cd5\u5982\u4f55\u4fee\u6539\u5c5e\u6027\u503c\uff1f"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1038\" src=\"https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/173024841613556.jpg\" width=\"800\" height=\"320\" srcset=\"https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/173024841613556.jpg 800w, https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/173024841613556-300x120.jpg 300w, https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/173024841613556-768x307.jpg 768w, https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/173024841613556-670x268.jpg 670w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" title=\"Python \u7c7b\u4e2d\u65b9\u6cd5\u5982\u4f55\u4fee\u6539\u5c5e\u6027\u503c\uff1f\u63d2\u56fe\" alt=\"Python \u7c7b\u4e2d\u65b9\u6cd5\u5982\u4f55\u4fee\u6539\u5c5e\u6027\u503c\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5173\u4e8epython\u7c7b\u4e2d\u65b9\u6cd5\u4fee\u6539\u5c5e\u6027\u503c<\/strong><\/p>\n<p>\u5728python\u7c7b\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u65b9\u6cd5\u4fee\u6539\u5c5e\u6027\u503c\u3002\u65b9\u6cd5\u4e2d\u7684\u8d4b\u503c\u8bed\u53e5\u4e0d\u4f7f\u7528return\u8fd4\u56de\uff0c\u8fd9\u662f\u56e0\u4e3a+=\u7b49\u64cd\u4f5c\u7b26\u662f\u4e00\u4e2a\u8bed\u53e5\uff0c\u800c\u4e0d\u662f\u8868\u8fbe\u5f0f\u3002\u8868\u8fbe\u5f0f\u53ef\u4ee5\u8d4b\u503c\u7ed9\u53d8\u91cf\u6216\u8fd4\u56de\uff0c\u800c\u8bed\u53e5\u53ea\u80fd\u72ec\u7acb\u6267\u884c\u3002<\/p>\n<p>\u76f8\u53cd\uff0c\u5982\u679c\u65b9\u6cd5\u4e2d\u4f7f\u7528print()\u51fd\u6570\u53d6\u4ee3return\uff0c\u90a3\u4e48\u65b9\u6cd5\u5c06\u8fd4\u56denone\u3002\u8fd9\u662f\u56e0\u4e3aprint()\u672c\u8eab\u4e0d\u8fd4\u56de\u4efb\u4f55\u503c\uff0c\u76f8\u5f53\u4e8ereturn none\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u4ee3\u7801\u7684\u793a\u4f8b\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201cPython\u514d\u8d39\u5b66\u4e60\u7b14\u8bb0\uff08\u6df1\u5165\uff09\u201d\uff1b<\/p>\n<pre>class dog:\n    def __init__(self, name, age):\n        self.name = name\n        self.age = age\n\n    def a(self, c):\n        \"\"\"\u5c06p\u8bbe\u7f6e\u6210\u6307\u5b9a\u589e\u52a0\u7684\u503c\"\"\"\n        self.p += c\n\n    def sit(self):\n        \"\"\"\u6a21\u62df\u5c0f\u72d7\u88ab\u547d\u4ee4\u65f6\u8e72\u4e0b\"\"\"\n        return self.name.title() + \" is now sitting.\"\n\nmy_dog = dog('\u5c0f\u767d', 10)\nmy_dog.a(2)\nprint(my_dog.p)\nprint(my_dog.sit())<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n<pre>6\n\u5c0f\u767d is now sitting.<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fPython \u7c7b\u4e2d\u65b9\u6cd5\u5982\u4f55\u4fee\u6539\u5c5e\u6027\u503c\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5173\u4e8epython\u7c7b\u4e2d\u65b9\u6cd5\u4fee\u6539\u5c5e\u6027\u503c \u5728python\u7c7b\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u65b9\u6cd5\u4fee\u6539\u5c5e\u6027\u503c\u3002\u65b9\u6cd5\u4e2d\u7684\u8d4b\u503c\u8bed\u53e5\u4e0d\u4f7f\u7528return\u8fd4\u56de\uff0c\u8fd9\u662f\u56e0\u4e3a+=\u7b49\u64cd\u4f5c\u7b26\u662f\u4e00\u4e2a\u8bed\u53e5\uff0c\u800c\u4e0d\u662f\u8868\u8fbe\u5f0f\u3002\u8868\u8fbe\u5f0f\u53ef\u4ee5\u8d4b\u503c\u7ed9\u53d8\u91cf\u6216\u8fd4\u56de\uff0c\u800c\u8bed\u53e5\u53ea\u80fd\u72ec\u7acb\u6267\u884c\u3002 \u76f8\u53cd\uff0c\u5982\u679c\u65b9\u6cd5\u4e2d\u4f7f\u7528print()\u51fd\u6570\u53d6\u4ee3return\uff0c\u90a3\u4e48\u65b9\u6cd5\u5c06\u8fd4\u56denone\u3002\u8fd9\u662f\u56e0\u4e3aprint()\u672c\u8eab\u4e0d\u8fd4\u56de\u4efb\u4f55\u503c\uff0c\u76f8\u5f53\u4e8ereturn none\u3002 \u4ee5\u4e0b\u662f\u4ee3\u7801\u7684\u793a\u4f8b\uff1a \u7acb\u5373\u5b66\u4e60\u201cPython\u514d\u8d39\u5b66\u4e60\u7b14\u8bb0\uff08\u6df1\u5165\uff09\u201d\uff1b class dog: def __init__(self, name, age): self.name = name self.age = age def a(self, c): &#8220;&#8221;&#8221;\u5c06p\u8bbe\u7f6e\u6210\u6307\u5b9a\u589e\u52a0\u7684\u503c&#8221;&#8221;&#8221; self.p += c def sit(self): &#8220;&#8221;&#8221;\u6a21\u62df\u5c0f\u72d7\u88ab\u547d\u4ee4\u65f6\u8e72\u4e0b&#8221;&#8221;&#8221; return self.name.title() + &#8221; is now sitting.&#8221; my_dog = dog(&#8216;\u5c0f\u767d&#8217;, 10) my_dog.a(2) print(my_dog.p) print(my_dog.sit()) \u767b\u5f55\u540e\u590d\u5236 \u8fd0\u884c\u7ed3\u679c\uff1a 6 \u5c0f\u767d is now sitting. \u767b\u5f55\u540e\u590d\u5236 \u4ee5\u4e0a\u5c31\u662fPython \u7c7b\u4e2d\u65b9\u6cd5\u5982\u4f55\u4fee\u6539\u5c5e\u6027\u503c\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-867","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/867","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=867"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/867\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=867"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=867"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=867"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}