page592.html
来自「Data Structures And Algorithms With Obje」· HTML 代码 · 共 42 行
HTML
42 行
<HTML><HEAD><TITLE>Instances, Instance Attributes and Methods</TITLE></HEAD><BODY bgcolor="#FFFFFF"> <a href="../index.html" target="_top"><img src="../icons/usins.gif" alt="Logo" align=right></a><b>Data Structures and Algorithms with Object-Oriented Design Patterns in Python</b><br><A NAME="tex2html7957" HREF="page593.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html7955" HREF="page591.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html7949" HREF="page591.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html7959" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H2><A NAME="SECTION0017410000000000000000">Instances, Instance Attributes and Methods</A></H2><P>Python objects are <em>instances</em><A NAME=56930> </A> of classes.Each instance (object) in a Python program has its own namespace.<P>A class definition creates a class object (type <tt>classobj</tt>).The names in the namespace of a class object are called<em>class attributes</em><A NAME=56933> </A><A NAME=56934> </A>.Function definitions inside of a class statement create <em>methods</em>.Methods are functions that process instances.<P>When an object is created,its namespace inherits all the names in the namespaceof the class of that object.The names in the namespace of an instance are called the<em>instance attributes</em><A NAME=56937> </A><A NAME=56938> </A>of that instance.<P>A method is a function created in a class definition.The first argument of a method always refersto the instance being processed.By convention,the first argument of a method is always named <tt>self</tt>.Therefore, the attributes of <tt>self</tt> are instance attributes.<P><HR><A NAME="tex2html7957" HREF="page593.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html7955" HREF="page591.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html7949" HREF="page591.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html7959" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <P><ADDRESS><img src="../icons/bruno.gif" alt="Bruno" align=right><a href="../copyright.html">Copyright © 2003</a> by <a href="../signature.html">Bruno R. Preiss, P.Eng.</a> All rights reserved.</ADDRESS></BODY></HTML>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?