[Tutor] Local variables and functions
rcsmith at speakeasy.net
Mon Nov 10 21:54:37 EST 2003
I have been reading "How To Think Like a Computer Scientist" to learn how to
program in python since I am a complete newbie. I am having problems with
declaring variables. Namely when they are local to a function. Below is an
example that I have been working on:
fruit = "bananna"
count = 0
for char in fruit:
count = count + 1
If I make the fruit variable global the function works, however when I have
it local to the function, I get a
NameError: name 'fruit' is not defined, error message. Can someone please
point out what I maybe missing? The concept of local variables seems pretty
straight forward, but I have been struggling with this issue since the 4th
chapter. I tried searching on google to see if someone else was having a
similar problem, but to no avail.
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 1972 bytes
Desc: not available
Url : http://mail.python.org/pipermail/tutor/attachments/20031110/1d2903cc/winmail.bin
More information about the Tutor