|
Size: 1278
Comment:
|
Size: 1294
Comment:
|
| Deletions are marked like this. | Additions are marked like this. |
| Line 4: | Line 4: |
| :status: 草稿|校对|正式;AuthorName;完成度15%; | :status: 草稿|校对|正式;HuangYi;完成度10%; |
| Line 9: | Line 9: |
| ======== | |
| Line 14: | Line 14: |
定义类 ======= :: 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 20: | Line 42: |
| -------------------- 引用:: This is the main heading ======================== :Status: Draft MoinMoin 链接: - `page with a ReStructuredText primer <HelpOnParsers/ReStructuredText/RstPrimer>`_ - `use of ReST in MoinMoin <HelpOnParsers/ReStructuredText>`_. 外部链接: - `Docutils-Users mailing list`_ - `Docutils project web site`_ .. [#] If that relative link doesn't work, try the master document: http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html. .. _Docutils-Users mailing list: http://lists.sourceforge.net/lists/listinfo/docutils-users .. _Docutils project web site: http://docutils.sourceforge.net/ |
===== |
: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)]]]