四、面向对象
class Document(): # 类对象
a = xx # 类属性
def __init__(self, title, author, context):
print('init function called')
self.title = title # 实例属性
self.author = author
self.__context = context # __开头的属性是私有属性
def get_context_length(self):
return len(self.__context)
def intercept_context(self, length):
self.__context = self.__context[:length]
harry_potter_book = Document('Harry Potter', 'J. K. Rowling', '... Forever Do not believe any thing is capable of thinking independently ...') # 实例对象
print