zoukankan      html  css  js  c++  java
  • python 继承

    继承:
    class Entity():
        # def __init__(self, object_type):
        #     print('parent class init called')
        #     self.object_type = object_type
    
        def get_context_length(self):
            raise Exception('get_context_length not implemented')
    
        def print_title(self):
            print(self.title)
    
    
    
    
    class Video(Entity):
        def __init__(self, title, author, video_length):
            print('Video class init called')
           # Entity.__init__(self, 'video')
            self.title = title
            self.author = author
            self.__video_length = video_length
    
        def get_context_length(self):
            return self.__video_length
    
    
    
    harry_potter_movie = Video('Harry Potter(Movie)', 'J. K. Rowling', 120)
    
    print dir(harry_potter_movie)
    print harry_potter_movie.get_context_length()
    
    C:Python27python.exe "C:/Users/TLCB/PycharmProjects/untitled2/python study/t12.py"
    Video class init called
    ['_Video__video_length', '__doc__', '__init__', '__module__', 'author', 'get_context_length', 'print_title', 'title']
    120
    
    Process finished with exit code 0
  • 相关阅读:
    java9新特性-9-语法改进:try语句
    10.04 FZSZ模拟Day1 总结
    10.03模拟总结
    HNOI2012 永无乡
    ZJOI2007 报表统计
    HNOI2004 宠物收养场
    HNOI2002 营业额统计
    Splay 区间反转
    Splay基本操作
    HEOI2016 树
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13348376.html
Copyright © 2011-2022 走看看