sending string or list to a function
Peter Otten
__peter__ at web.de
Tue Dec 5 03:49:14 EST 2006
tleeuwenburg at gmail.com wrote:
> Or, just always send the function a list. If you have one string, send
> it a list containing that one string.
Or, if a single string is more common and the lists are short or generated
only for the function call, have the function accept a variable number of
arguments:
>> def my_function(*items):
... print " ".join(items)
...
>>> my_function("alpha")
alpha
>>> my_function("alpha", "beta")
alpha beta
>>> items = ["alpha", "beta", "gamma"]
>>> my_function(*items)
alpha beta gamma
Peter
More information about the Python-list
mailing list