problem using using list with function

Ken Seehof kseehof at neuralintegrator.com
Wed Oct 10 04:21:45 EDT 2001


> 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