![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
|
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)
__________________
http://exponentialab.blogspot.com/ - w00t, I've started a blog! |
|
|
|
|
|
#2 |
|
Expert Programmer
|
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 >>> def testTwo(a): ... return a; >>> 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! |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|