zoukankan      html  css  js  c++  java
  • (转)面向对象编程初步

    复制代码
    1 class Hand:
     2     pass
     3 class Foot:
     4     pass
     5 class Trunk:
     6     pass
     7 class Head:
     8     pass
     9 
    10 class Person:
    11     def __init__(self,id_num,name,hand,foot,trunk,head):
    12         self.id_num=id_num
    13         self.name=name
    14         self.hand=Hand()
    15         self.foot=Foot()
    16         self.trunk=Trunk()
    17         self.head=Head()
    复制代码
    复制代码
    class School:
        def __init__(self,name,addr):
            self.name=name
            self.addr=addr
    
    </span><span style="color: #0000ff">def</span><span style="color: #000000"> tell_info(self):
        </span><span style="color: #0000ff">print</span>(<span style="color: #800000">'</span><span style="color: #800000">School(%s,%s)</span><span style="color: #800000">'</span> %<span style="color: #000000">(self.name,self.addr))
    

    class Course:
    def init(self,name,price,period):
    self.name
    =name
    self.price
    =price
    self.period
    =period

        self.school</span>=School(<span style="color: #800000">'</span><span style="color: #800000">oldboy</span><span style="color: #800000">'</span>,<span style="color: #800000">'</span><span style="color: #800000">沙河</span><span style="color: #800000">'</span><span style="color: #000000">)
    

    c1=Course('python',15000,'5month')
    print(c1.name)
    c1.school.tell_info()

    复制代码

    面向对象编程

     

    转自:
    面向对象编程初步 - tonador - 博客园
    https://www.cnblogs.com/yujianbao/articles/6223482.html

  • 相关阅读:
    codeforces 980A Links and Pearls
    zoj 3640 Help Me Escape
    sgu 495 Kids and Prizes
    poj 3071 Football
    hdu 3853 LOOPS
    hdu 4035 Maze
    hdu 4405 Aeroplane chess
    poj 2096 Collecting Bugs
    scu 4444 Travel
    zoj 3870 Team Formation
  • 原文地址:https://www.cnblogs.com/jyfootprint/p/9468240.html
Copyright © 2011-2022 走看看