Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Aug 5th, 2004, 6:48 PM   #1
G.I.Josh
Programmer
 
G.I.Josh's Avatar
 
Join Date: Aug 2004
Location: Eastern U.S
Posts: 51
Rep Power: 5 G.I.Josh is on a distinguished road
Send a message via AIM to G.I.Josh
I'm having a difficult time grasping the concept of returning values in functions. Here is what I think I know. If you have a function like
def welcome_message(name):
  print name
welcome_message(G.I.Josh)
It will store the value G.I.Josh in a variable called name. Now, if I added return G.I.Josh, what exactly would happen? Also, if I needed to get more then one variable from outside of the function into the function, how could I do that? And lastly. How can I keep variables I manipulate inside the function from going back to their orriginal value once the function is over? Thanks.
__________________
http://exponentialab.blogspot.com/ - w00t, I've started a blog!
G.I.Josh is offline   Reply With Quote
Old Aug 6th, 2004, 12:09 PM   #2
thechristelegacy
Expert Programmer
 
thechristelegacy's Avatar
 
Join Date: Jul 2004
Location: Somerset, Pa
Posts: 708
Rep Power: 5 thechristelegacy is on a distinguished road
Send a message via AIM to thechristelegacy Send a message via MSN to thechristelegacy
Alright, when you code
def welcome_message(name):
 print name
welcome_message(G.I.Josh)

all it does is print the value, but it doesn't assign it to a variable. For example I'll show you two comparisons of using it and not using it..

>>> def testOne(a):
...     print a
and
>>> def testTwo(a):
...     return a;
Here is what you would get when you run each one.

>>> a = testOne('Hello, World.')
Hello, World.


But that value isn't assigned to a you'll see if you try to print a this happens.


>>> print t
None


You'll see that no value is stored for it. But when you run the second one with the return statement. It does send a value back to the variable as shown.


>>> a = testTwo('Hello, World.')
>>> print a
Hello, World.


Hope that helps. Just know that return passes the value to the variable. Good luck!
thechristelegacy is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:27 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC