problem using using list with function

adam griffin dokkenrox at earthlink.net
Wed Oct 10 17:52:27 EDT 2001


I think I figured out my problem. I had the function definition at the end
of my script when I put it at the beginning it worked. is this the only
place you can put definitions?

"Ken Seehof" <kseehof at neuralintegrator.com> wrote in message
news:mailman.1002701769.4408.python-list at python.org...
> > i'm trying to write a function that takes a list as it's only arguement
> and
> > also has a list as it's return value. this is sort of what it looks
like:
> >
> > list1 = [ 1, 2, 3];
> >
> > list2 = function(list1)
> >
> > def function(listArguement):
> >     #statements...
> >     return list
>
> Looks like you are on the right track.  Try this in your python
interpreter.
> You can learn a lot by trying things in the interpreter to see what
happens.
>
> >>> def spam_and(a):
> ...  b = ['spam', 'spam'] + a
> ...  return b
> ...
> >>> list1 = [ 1, 2, 3]
> >>> list2 = spam_and(list1)
> >>> print list2
> ['spam', 'spam', 1, 2, 3]
> >>>
>
>
>
>
>
>





More information about the Python-list mailing list