{"id":315,"date":"2024-04-29T00:00:35","date_gmt":"2024-04-28T16:00:35","guid":{"rendered":"https:\/\/669082.xyz\/?p=315"},"modified":"2024-04-29T00:17:07","modified_gmt":"2024-04-28T16:17:07","slug":"20240428%e5%ad%a6%e4%b9%a0python_%e9%9d%a2%e5%90%91%e5%af%b9%e8%b1%a1","status":"publish","type":"post","link":"https:\/\/669082.xyz\/index.php\/2024\/04\/29\/20240428%e5%ad%a6%e4%b9%a0python_%e9%9d%a2%e5%90%91%e5%af%b9%e8%b1%a1\/","title":{"rendered":"20240428\u5b66\u4e60Python_\u9762\u5411\u5bf9\u8c61"},"content":{"rendered":"<pre><code class=\"language-python\">#\u7c7b\u4e0e\u5bf9\u8c61\nclass Person:\n  def __init__(self, name, age):\n    self.name = name\n    self.age = age\np1 = Person(&quot;Bill&quot;, 63)\nprint(p1.name)\nprint(p1.age)\n\nclass Person:\n  def __init__(self, name, age):\n    self.name = name\n    self.age = age\n  def myfunc(self):\n    print(&quot;Hello my name is &quot; + self.name)\np1 = Person(&quot;Bill&quot;, 63)\np1.myfunc()\n\n#\u6539\u6389\u7c7b\u65b9\u6cd5\u91cc\u7684\u53c2\u6570 self\nclass Person:\n  def __init__(mysillyobject, name, age):\n    mysillyobject.name = name\n    mysillyobject.age = age\n\n  def myfunc(abc):\n    print(&quot;Hello my name is &quot; + abc.name)\n\np1 = Person(&quot;Bill&quot;, 63)\np1.myfunc()\n\n#\u7c7b\u7684\u7ee7\u627f\nclass Person:\n  def __init__(self, fname, lname):\n    self.firstname = fname\n    self.lastname = lname\n\n  def printname(self):\n    print(self.firstname, self.lastname)\n\nclass Student(Person): #\u8fd9\u91cc\u7ee7\u627f\u4e86 Person\u7c7b\n  pass\n\nx = Student(&quot;Elon&quot;, &quot;Musk&quot;)\nx.printname()\n\n#\u4e5f\u53ef\u4ee5\u5728\u5b50\u7c7b\u4e2d\u521b\u5efainit\u6784\u9020\u65b9\u6cd5\nclass Student(Person):\n  def __init__(self, fname, lname):\n    Person.__init__(self, fname, lname)\n\nclass Student(Person):\n  def __init__(self, fname, lname):\n    super().__init__(fname, lname)\n\n#\u5b50\u7c7b\u4e2d\u7684\u6784\u9020\u65b9\u6cd5\u91cc\u4e5f\u53ef\u4ee5\u6dfb\u52a0\u5c5e\u6027\nclass Student(Person):\n  def __init__(self, fname, lname):\n    super().__init__(fname, lname)\n    self.graduationyear = 2019\n\n#\u7ee7\u627f\u540e\u6dfb\u52a0\u65b9\u6cd5\nclass Student(Person):\n  def __init__(self, fname, lname, year):\n    super().__init__(fname, lname)\n    self.graduationyear = year\n\n  def welcome(self):\n    print(&quot;Welcome&quot;, self.firstname, self.lastname, &quot;to the class of&quot;, self.graduationyear)\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>#\u7c7b\u4e0e\u5bf9\u8c61 class Person: def __init__(self, name, age): [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-315","post","type-post","status-publish","format-standard","hentry","category-python"],"_links":{"self":[{"href":"https:\/\/669082.xyz\/index.php\/wp-json\/wp\/v2\/posts\/315","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/669082.xyz\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/669082.xyz\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/669082.xyz\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/669082.xyz\/index.php\/wp-json\/wp\/v2\/comments?post=315"}],"version-history":[{"count":3,"href":"https:\/\/669082.xyz\/index.php\/wp-json\/wp\/v2\/posts\/315\/revisions"}],"predecessor-version":[{"id":319,"href":"https:\/\/669082.xyz\/index.php\/wp-json\/wp\/v2\/posts\/315\/revisions\/319"}],"wp:attachment":[{"href":"https:\/\/669082.xyz\/index.php\/wp-json\/wp\/v2\/media?parent=315"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/669082.xyz\/index.php\/wp-json\/wp\/v2\/categories?post=315"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/669082.xyz\/index.php\/wp-json\/wp\/v2\/tags?post=315"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}