Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Destruct Python List as Function Arguments [duplicate]

How to destruct array to argument list like in javascript?

def foo( arg0, arg1 ): pass
bar = [ 32, 44 ]
foo( ...bar )
like image 531
Pierre Dunn Avatar asked Dec 22 '22 23:12

Pierre Dunn


1 Answers

It's called argument unpacking. Use the *args format

foo(*bar)

More info: https://www.geeksforgeeks.org/packing-and-unpacking-arguments-in-python/

like image 63
rdas Avatar answered Jan 05 '23 16:01

rdas