Unpacking arguments: only named arguments may follow *expression

后端 未结 6 542
长情又很酷
长情又很酷 2020-12-03 09:18

The following works beautifully in Python:

def f(x,y,z): return [x,y,z]

a=[1,2]

f(3,*a)

The elements of a get unpacked as if

6条回答
  •  囚心锁ツ
    2020-12-03 10:10

    Nice. This also works for tuples. Don't forget the comma:

    a = (1,2)
    f(*(a+(3,)))
    

提交回复
热议问题