106.html
来自「Python Ebook Python&XML」· HTML 代码 · 共 48 行
HTML
48 行
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Robots" content="INDEX,NOFOLLOW">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<TITLE>Safari | Python Developer's Handbook -> Python Classes and Instances</TITLE>
<LINK REL="stylesheet" HREF="oreillyi/oreillyN.css">
</HEAD>
<BODY bgcolor="white" text="black" link="#990000" vlink="#990000" alink="#990000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="100%" cellpadding=5 cellspacing=0 border=0 class="navtopbg"><tr><td><font size="1"><p class="navtitle"><a href="8.html" class="navtitle">Web Development</a> > <a href="0672319942.html" class="navtitle">Python Developer's Handbook</a> > <a href="102.html" class="navtitle">5. Object-Oriented Programming</a> > <span class="nonavtitle">Python Classes and Instances</span></p></font></td><td align="right" valign="top" nowrap><font size="1"><a href="main.asp?list" class="safnavoff">See All Titles</a></font></td></tr></table>
<TABLE width=100% bgcolor=white border=0 cellspacing=0 cellpadding=5><TR><TD>
<TABLE border=0 width="100%" cellspacing=0 cellpadding=0><TR><td align=left width="15%" class="headingsubbarbg"><a href="105.html" title="An Introduction to Python OOP"><font size="1">< BACK</font></a></td><td align=center width="70%" class="headingsubbarbg"><font size="1"><a href="popanote.asp?pubui=oreilly&bookname=0672319942&snode=106" target="_blank" title="Make a public or private annnotation">Make Note</a> | <a href="106.html" title="Use a Safari bookmark to remember this section">Bookmark</a></font></td><td align=right width="15%" class="headingsubbarbg"><a href="107.html" title="Methods Handling"><font size="1">CONTINUE ></font></a></td></TR></TABLE>
<a href="5%2F31%2F2002+4%3A33%3A18+PM.html" TABINDEX="-1"><img src=images/spacer.gif border=0 width=1 height=1></a><font color=white size=1>152015024128143245168232148039199167010047123209178152124239215162147039203229248005010102</font><a href="read9.asp?bookname=0672319942&snode=106&now=5%2F31%2F2002+4%3A33%3A18+PM" TABINDEX="-1"><img src=images/spacer.gif border=0 width=1 height=1></a><br>
<FONT>
<h3>Python Classes and Instances</h3>
<p>In Python, a class is a user-defined data type, and as in most other languages, you define Python classes using the keyword <a NAME="idx1073743310"></a><a naME="idx1073743311"></A><Tt claSS="monofont">class.</TT></p>
<pre>
class <i><class name>:</i>
<i><class statements></i>
</pre>
<p>The <a name="idx1073743312"></a><a nAme="idx1073743313"></A><i>class statements</i> section contains any valid Python statement that defines class constants or class methods. Note that the contents of the variable namespace formed by executing the commands in the class statement make up the class dictionary.</p>
<P>Two ways to create classes are</p>
<ul>
<lI><p>You can define it from scratch.</p>
<pRE>
class <I><class name>:</I>
<i>["documentation text"]</i>
<i><class statements></i>
</PRE>
</Li>
<li><p>You can create a new class that inherits properties of other classes. This is called <I>subclassing,</I> and you will learn more about it later in this chapter.</P>
<Pre>
class <i><class name> [(baseclass1, baseclass2,
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?