phoenix13

导航

 

http://www.17jo.com/program/python/base/ClassUse.html   Python 类的定义、继承及使用对象

http://blog.csdn.net/wklken/article/details/6313265   Python笔记——类定义

 

# 例:类定义及使用
class CAnimal:
    name = 'unname' # 成员变量 
    def __init__(self,voice='hello'):    # 重载构造函数
        self.voice = voice            # 创建成员变量并赋初始值
    def __del__(self):              # 重载析构函数
        pass                # 空操作
    def Say(self):
        print self.voice

t = CAnimal()        # 定义动物对象t
t.Say()        # t说话
>> hello            # 输出
dog = CAnimal('wow')    # 定义动物对象dog
dog.Say()            # dog说话
>> wow            # 输出
posted on 2012-12-02 15:47  phoenix13  阅读(223)  评论(0编辑  收藏  举报