[Tutor] Newbie Question: Define Funcations
MBussell@aol.com
MBussell@aol.com
Fri, 17 May 2002 21:45:51 EDT
--part1_23.1e5a1bc6.2a170c4f_boundary
Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: 7bit
Dear Tutor:
I am attempting to learn my first language, and am having some trouble with
defining functions. I understand the theory - but the application does not
seem to perform like the two text's I have downloaded.
>From my understanding, the parameter is the name used inside a function to
refer to the value passed as an argument. Example:
def printtwice(bruce):
print bruce, bruce
printtwice(spam)
Theoretical output:
spam spam
Actual output:
Traceback (most recent call last):
File "<pyshell#3>", line 1, in ?
printtwice(spam)
NameError: name 'spam' is not defined
Do I have to define the argument before I use it in a function (thought one
of the benefits of a function was to assign an argument to the value)?
Thanks,
Andy
--part1_23.1e5a1bc6.2a170c4f_boundary
Content-Type: text/html; charset="US-ASCII"
Content-Transfer-Encoding: 7bit
<HTML><FONT FACE=arial,helvetica><FONT SIZE=2>Dear Tutor:
<BR>
<BR>I am attempting to learn my first language, and am having some trouble with defining functions. I understand the theory - but the application does not seem to perform like the two text's I have downloaded.
<BR>
<BR>From my understanding, the parameter is the name used inside a function to refer to the value passed as an argument. Example:
<BR>
<BR> def printtwice(bruce):
<BR> print bruce, bruce
<BR>
<BR> printtwice(spam)
<BR>Theoretical output:
<BR> spam spam
<BR>
<BR>Actual output:
<BR> Traceback (most recent call last):
<BR> File "<pyshell#3>", line 1, in ?
<BR> printtwice(spam)
<BR>NameError: name 'spam' is not defined
<BR>
<BR>Do I have to define the argument before I use it in a function (thought one of the benefits of a function was to assign an argument to the value)?
<BR>
<BR>Thanks,
<BR>Andy</FONT></HTML>
--part1_23.1e5a1bc6.2a170c4f_boundary--