page587.html

来自「Data Structures And Algorithms With Obje」· HTML 代码 · 共 63 行

HTML
63
字号
<HTML><HEAD><TITLE>Names</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="tex2html7898" HREF="page588.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html7896" HREF="page585.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html7890" HREF="page586.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html7900" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H1><A NAME="SECTION0017200000000000000000">Names</A></H1><P>In order to make use of an object in a Python program,that object must have a <em>name</em><A NAME=56853>&#160;</A>.The name of an object is the labelused to identify that object in the text of a program.A given Python object may have zero, one or more names.<P>Consider the Python statement:<PRE>i = 57</PRE>This statement creates an object named <tt>i</tt>and <em>binds</em><A NAME=56856>&#160;</A> various attributes with that object.The type of the object is <tt>int</tt>and its value is 57.<P>Some attributes of an object, such its type,are bound when the object is created and cannot be changed.This is called <em>static binding</em>.The bindings for other attributes of an object, such as its value,may be changed at run time.This is called <em>dynamic binding</em>.<P>Consider again the Python statement:<PRE>i = int(57)</PRE>If we follow this statement with an assignment statement such as<PRE>j = i</PRE>then the names <tt>i</tt> and <tt>j</tt> both refer to the same object!<P>A comparison of the the form<PRE>if i == j:    print &quot;equal values&quot;</PRE>tests whether the value of the object named <tt>i</tt>is the same as the value of the object named <tt>j</tt>.(Clearly this is true since <tt>i</tt> and <tt>j</tt> name the same object).However,it is possible for two distinct objects to have the same value.In order to test whether two names refer to the same object,it is necessary to Python <tt>is</tt> operator like this:<PRE>if i is j:    print &quot;same object&quot;</PRE><P><BR> <HR><UL> <LI> <A NAME="tex2html7901" HREF="page588.html#SECTION0017201000000000000000">The Object Named <tt>None</tt></A><LI> <A NAME="tex2html7902" HREF="page589.html#SECTION0017210000000000000000">Scopes and Namespaces</A></UL><HR><A NAME="tex2html7898" HREF="page588.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html7896" HREF="page585.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html7890" HREF="page586.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html7900" 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 &#169; 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 + -
显示快捷键?