I have a list...

Bengt Richter bokr at oz.net
Wed Jul 2 01:48:15 CEST 2003


On Tue, 1 Jul 2003 11:39:15 +0400, "Damir Hakimov" <agg at astranet.ru> wrote:

>Hi, All!
>
>say, i have a function:
>
>def f(*b):
>  print b
>  return
>
>then i do:
>f(3,4,5)
>(3, 4, 5)
>
>but i have list f=(3,4,5)
>f(l)
>((3, 4, 5),)    
>
>how can i call f function to result
>f(???(b))
>(3, 4, 5)
>
Is this what you are looking for? :

 >>> def f(*b):
 ...     print b
 ...
 >>> tup = (1,2,3)
 >>> f(tup)
 ((1, 2, 3),)

tup was single arg, but:

 >>> f(*tup)
 (1, 2, 3)

tup got unpacked to make args

 >>> L = [4,5,6]
 >>> f(L)
 ([4, 5, 6],)

L was single arg, but:

 >>> f(*L)
 (4, 5, 6)

L got unpacked similarly, but note that args become tuple b, not a list.

Regards,
Bengt Richter




More information about the Python-list mailing list