⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 page590.html

📁 Data Structures And Algorithms With Object-Oriented Design Patterns In Python (2003) source code and
💻 HTML
字号:
<HTML><HEAD><TITLE>Parameter Passing</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="tex2html7929" HREF="page591.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html7927" HREF="page585.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html7921" HREF="page589.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html7931" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H1><A NAME="SECTION0017300000000000000000">Parameter Passing</A></H1><P>Parameter passing methods<A NAME=56891>&#160;</A>are the ways in which parametersare transfered between methods when one method calls another.Python provides only one parameter passing method--<em>pass-by-reference</em><A NAME=56893>&#160;</A>.<P>Consider the pair of Python methods defined in Program&nbsp;<A HREF="page590.html#progexamplev"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>.On line&nbsp;4, the method <tt>one</tt> calls the method <tt>two</tt>.In general,every method call includes a (possibly empty) list of arguments.The arguments specified in a method call are called<em>actual parameters</em><A NAME=56898>&#160;</A>.In this case, there is only one actual parameter--<tt>x</tt>.<P><P><A NAME="56903">&#160;</A><A NAME="progexamplev">&#160;</A> <IMG WIDTH=575 HEIGHT=202 ALIGN=BOTTOM ALT="program56900" SRC="img2484.gif"  ><BR><STRONG>Program:</STRONG> Example of parameter passing.<BR><P><P>On line&nbsp;7 the method <tt>two</tt> is definedas accepting a single argument <tt>y</tt>.The arguments which appear in a method definition are called<em>formal parameters</em><A NAME=56911>&#160;</A>.<P>The semantics of pass-by-reference work like this:The effect of the formal parameter definition is to createa name in the local namespace of the function andthen to bind that name to the object named by the actual parameter.For example,in the method <tt>two</tt> the formal parameter is called <tt>y</tt>.When the method is called,the name <tt>y</tt> is assigned to the object named <tt>x</tt>.<P>Since the formal parameters give rise to names in the local namespace,when a formal parameter is assigneda new object is bound to that name in the local namespace.The object named by the actual parameter is no longer accessible.<P>The output produced when the method <tt>one</tt>defined in Program&nbsp;<A HREF="page590.html#progexamplev"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A> is called is:<PRE>1121</PRE><P><HR><A NAME="tex2html7929" HREF="page591.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html7927" HREF="page585.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html7921" HREF="page589.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html7931" 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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -