Differences between revisions 3 and 4
Revision 3 as of 2007-06-26 05:55:26
Size: 707
Editor: HuangYi
Comment:
Revision 4 as of 2007-06-27 01:19:44
Size: 1294
Editor: HuangYi
Comment:
Deletions are marked like this. Additions are marked like this.
Line 18: Line 18:
继承
=======
::
  
  class Klass(object):
      def __init__(self):
          self.a = 1

关键字 ``class`` 就是用来定义一个类的, ``Klass`` 是类的名字,括号中 ``object`` 表示继承 ``object`` 这个 ``class`` ,python 中所有的 ``class`` 都是从 ``object`` 继承而来(虽然在目前的 python 版本中还存在一类所谓 old-style class 是不从 object 继承而来的,不过那个早已过时并在 python3.0 中彻底退出历史舞台,所以我们这里只当它不存在了)。

在冒号之后的 class 定义体中,你就可以定义任意的属性了。
Line 22: Line 29:
--------- ========
Rendering of reStructured text is not possible, please install Docutils.
:status: 草稿|校对|正式;HuangYi;完成度10%;

.. contents::
  :depth: 3

========
类与实例
========

通常大家说的都是"类与对象",不过 python 中万物皆对象,对象这个词语不免让人产生误会,实际上我们这里要讨论的是用户自定义的类和这些类的实例,类与实例都是对象这个大概念中的一种。

定义类
=======

::
  
  class Klass(object):
      def __init__(self):
          self.a = 1

关键字 ``class`` 就是用来定义一个类的, ``Klass`` 是类的名字,括号中 ``object`` 表示继承 ``object`` 这个 ``class`` ,python 中所有的 ``class`` 都是从 ``object`` 继承而来(虽然在目前的 python 版本中还存在一类所谓 old-style class 是不从 object 继承而来的,不过那个早已过时并在 python3.0 中彻底退出历史舞台,所以我们这里只当它不存在了)。

在冒号之后的 class 定义体中,你就可以定义任意的属性了。

多重继承
========

属性
=======

方法
=======

小结
=====


练习
=====

.. macro:: [[PageComment2(nosmiley=1, notify=1)]]


.. macro:: -- HuangYi [[[DateTime(2007-06-26T05:39:25Z)]]]

ObpLovelyPython/LpyQLearn-5-object (last edited 2009-12-25 07:18:49 by localhost)