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
  • 相关阅读:
    C# 获取枚举集合的其中两种方式
    UITextField限制字数的方法
    iOS
    iOS
    iOS
    iOS 获取已连接的wifi信息
    AFNetWorking 的简单使用
    CoreData 基本操作方法封装
    在Ios里UIWebView参入js
    AFNetworking教程
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13348376.html
Copyright © 2011-2022 走看看