# !/usr/bin/env python
# -*- coding: utf-8 -*-
class Document():
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]
print type(Document)
harry_potter_book = Document('Harry Potter', 'J. K. Rowling', '... Forever Do not believe any thing is capable of thinking independently ...')
print type(harry_potter_book)
C:\Python27\python.exe C:/Users/TLCB/PycharmProjects/untitled2/socket/t21.py
<type 'classobj'>
init function called
<type 'instance'>
Process finished with exit code 0
class Document 定义了 Document 类,再往下能看到它有三个函数,这三个函数即为 Document 类的三个函数。
对象:集合中的一个事物,这里对应由 class 生成的某一个 object,
比如代码中的 harry_potter_book。