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
原文地址:https://www.cnblogs.com/hzcya1995/p/13348376.html