📄 105.html
字号:
<!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 -> An Introduction to Python OOP</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">An Introduction to Python OOP</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="104.html" title="Object-Oriented Programming"><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=105" target="_blank" title="Make a public or private annnotation">Make Note</a> | <a href="105.html" title="Use a Safari bookmark to remember this section">Bookmark</a></font></td><td align=right width="15%" class="headingsubbarbg"><a href="106.html" title="Python Classes and Instances"><font size="1">CONTINUE ></font></a></td></TR></TABLE>
<a href="5%2F31%2F2002+4%3A33%3A08+PM.html" TABINDEX="-1"><img src=images/spacer.gif border=0 width=1 height=1></a><font color=white size=1>152015024128143245168232148039199167010047123209178152124239215162147039203228119224069233</font><a href="read9.asp?bookname=0672319942&snode=105&now=5%2F31%2F2002+4%3A33%3A08+PM" TABINDEX="-1"><img src=images/spacer.gif border=0 width=1 height=1></a><br>
<FONT><h3>An Introduction to Python OOP</h3>
<p>A <a NAME="idx1073743249"></a><i>class</i> defines a category of objects in terms of the data it encapsulates and the operations on the data that are allowed by the interface functions. Essentially, a class is a template from which objects can be created.</p>
<P>Each object created from a class is an <A NAme="idx1073743250"></a><a NAME="idx1073743251"></a><i>instance</i> of a class. They all look alike and exhibit a similar behavior.</p>
<p>A class stores object <a name="idx1073743252"></a><i>attributes</i> (also known as data members) and the behavior of objects (mostly known as <i>methods</i>). This behavior can be inherited from other (<i>base</i>) <a naMe="idx1073743253"></a><A namE="idx1073743254"></a>classes. The non-method attributes of the class are usually referred to as <a naMe="idx1073743255"></a><a NAME="idx1073743256"></a><i>class members</i> or <a NAME="idx1073743257"></a><i>class attributes</i> so that they are not confused with <a NAME="idx1073743258"></a><a naME="idx1073743259"></A>instance attributes.<A name="idx1073743260"></a><a name="idx1073743261"></a></p>
<p>Each class has its own namespace in which all the assignments and function definitions occur.</p>
<h4>Class Instances</h4>
<p>A class instance is a Python object, and similar to every Python object, it has the following properties: <i>identity,</i>
<i>object type,</I>
<i>attributes,</i>
<I>methods,</i> and <i>value.</i></P>
<p>I will use the following class definition as the basis for the next explanations. First, let's declare the <tt cLass="monofont">c</TT> class, and then we will create an instance of this class called <TT clasS="monofont">obj.</TT></P>
<pre>
>>> class c:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -