[Tutor] Variables and Functions

Alan Gauld alan.gauld at btinternet.com
Thu Nov 29 02:01:59 CET 2007


"Devon MacIntyre" <macintyredev at gmail.com> wrote

> Just wondering, how would I get a variable out of one function and 
> into
> another?

return the value from one function and pass it as an argument to the 
other.
Example:

def oneFunction()
     x = [1,2,3]
     return x

def another(aValue):
     print aValue


def main():
    myList = oneFunction()
    another(myList)

Does that make any kind of sense to you?
For more on functions and arguments and parameter passing
see my tutorial topic on Modules and functions.

> called 'new_game()'. Also, I'm using a Mac, but I'm not sure if that 
> affects
> the code or not.

Nope, the Mac makes no difference whatsoever in this situation. :-)


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 




More information about the Tutor mailing list