<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Classes 类 — Python v3.0c1 documentation</title>
<link rel="stylesheet" href="../_static/default.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../',
VERSION: '3.0c1',
COLLAPSE_MODINDEX: false,
FILE_SUFFIX: '.html'
};
</script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<link rel="search" type="application/opensearchdescription+xml"
title="Search within Python v3.0c1 documentation"
href="../_static/opensearch.xml"/>
<link rel="author" title="About these documents" href="../about.html" />
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="copyright" title="Copyright" href="../copyright.html" />
<link rel="top" title="Python v3.0c1 documentation" href="../index.html" />
<link rel="up" title="The Python tutorial Python 入门指南" href="index.html" />
<link rel="next" title="Brief Tour of the Standard Library 标准库概览" href="stdlib.html" />
<link rel="prev" title="Errors and Exceptions 错误和异常" href="errors.html" />
</head>
<body>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../modindex.html" title="Global Module Index"
accesskey="M">modules</a> |</li>
<li class="right" >
<a href="stdlib.html" title="Brief Tour of the Standard Library 标准库概览"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="errors.html" title="Errors and Exceptions 错误和异常"
accesskey="P">previous</a> |</li>
<li><img src="../_static/py.png" alt="" style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="../contents.html">Python v3.0c1 documentation</a> »</li>
<li><a href="index.html" accesskey="U">The Python tutorial Python 入门指南</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<div class="section" id="classes">
<span id="tut-classes"></span><h1>Classes 类<a class="headerlink" href="#classes" title="Permalink to this headline">¶</a></h1>
<p>Python’s class mechanism adds classes to the language with a minimum of new
syntax and semantics. It is a mixture of the class mechanisms found in C++ and
Modula-3. As is true for modules, classes in Python do not put an absolute
barrier between definition and user, but rather rely on the politeness of the
user not to “break into the definition.” The most important features of classes
are retained with full power, however: the class inheritance mechanism allows
multiple base classes, a derived class can override any methods of its base
class or classes, and a method can call the method of a base class with the same
name. Objects can contain an arbitrary amount of private data.</p>
<p>Python 在尽可能不增加新的语法和语义的情况下加入了类机制。这种机制是 C++ 和 Modula-3 的混合。
Python中的类没有在用户和定义之间建立一个绝对的屏障,而是依赖于用户自觉的不去“破坏定义”。然而,
类机制最重要的功能都完整的保留下来:类继承机制允许多继承,派生类可以覆盖(override)基类中的任
何方法,方法中可以调用基类中的同名方法。对象可以包含任意数量的私有成员。</p>
<p>In C++ terminology, normally class members (including the data members) are
<em>public</em> (except see below <a class="reference internal" href="#tut-private"><em>Private Variables 私有变量</em></a>),
and all member functions are <em>virtual</em>. There are no special constructors or
destructors. As in Modula-3, there are no shorthands for referencing the
object’s members from its methods: the method function is declared with an
explicit first argument representing the object, which is provided implicitly by
the call. As in Smalltalk, classes themselves are objects, albeit in the wider
sense of the word: in Python, all data types are objects. This provides
semantics for importing and renaming. Unlike C++ and Modula-3, built-in types
can be used as base classes for extension by the user. Also, like in C++ but
unlike in Modula-3, most built-in operators with special syntax (arithmetic
operators, subscripting etc.) can be redefined for class instances.</p>
<p>用 C++ 术语来讲,所有的类成员(包括数据成员)都是*公有*(参见 <a class="reference internal" href="#tut-private"><em>Private Variables 私有变量</em></a> )的,所有
的成员函数都是*虚*( virtual )的。没有特定的构造和析构函数。像 Modula-3 一样,在成员方法中没
有什么简便的方式可以引用对象的成员:方法函数在定义时需要以引用的对象做为第一个参数,调用时则会隐式
引用对象。像 Smalltalk 一样,类本身就是对象,在更为广义的范围上理解: Python 中一切数据类型都
是对象。这样就形成了语义上的引入和重命名。但是,像 C++ 而非 Modula-3 中那样,大多数带有特殊语
法的内置操作符(算法运算符、下标等)都可以针对类的需要重新定义。</p>
<div class="section" id="a-word-about-terminology">
<span id="tut-terminology"></span><h2>A Word About Terminology 术语漫谈<a class="headerlink" href="#a-word-about-terminology" title="Permalink to this headline">¶</a></h2>
<p>Lacking universally accepted terminology to talk about classes, I will make
occasional use of Smalltalk and C++ terms. (I would use Modula-3 terms, since
its object-oriented semantics are closer to those of Python than C++, but I
expect that few readers have heard of it.)</p>
<p>由于没有什么关于类的通用术语,我从 Smalltalk 和 C++ 中借用一些(我更希望用 Modula-3 的,因
为它的面向对象机制比 C++更接近Python,不过我想没多少读者听说过它)。</p>
<p>Objects have individuality, and multiple names (in multiple scopes) can be bound
to the same object. This is known as aliasing in other languages. This is
usually not appreciated on a first glance at Python, and can be safely ignored
when dealing with immutable basic types (numbers, strings, tuples). However,
aliasing has an (intended!) effect on the semantics of Python code involving
mutable objects such as lists, dictionaries, and most types representing
entities outside the program (files, windows, etc.). This is usually used to
the benefit of the program, since aliases behave like pointers in some respects.
For example, passing an object is cheap since only a pointer is passed by the
implementation; and if a function modifies an object passed as an argument, the
caller will see the change — this eliminates the need for two different
argument passing mechanisms as in Pascal.</p>
<p>对象是被特化的,多个名字(在多个作用域中)可以绑定同一个对象。这相当于其它语言中的别名。通常对
Python 的第一印象中会忽略这一点,使用那些不可变的基本类型(数值、字符串、元组)时也可以很放心
的忽视它。然而,在 Python �
没有合适的资源?快使用搜索试试~ 我知道了~
python3中英文文档.rar
共15个文件
html:15个
3星 · 超过75%的资源 需积分: 10 59 下载量 72 浏览量
2008-12-13
06:58:42
上传
评论 2
收藏 184KB RAR 举报
温馨提示
python3中英文文档.rar python3中英文文档.rar
资源推荐
资源详情
资源评论
收起资源包目录
python3中英文文档.rar (15个子文件)
tutorial
errors.html 56KB
modules.html 76KB
controlflow.html 71KB
interactive.html 18KB
appetite.html 14KB
whatnow.html 9KB
stdlib.html 43KB
classes.html 100KB
datastructures.html 75KB
introduction.html 71KB
stdlib2.html 51KB
index.html 24KB
interpreter.html 32KB
inputoutput.html 53KB
floatingpoint.html 26KB
共 15 条
- 1
nyyjy010
- 粉丝: 0
- 资源: 27
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页