For example, if I have
a=[['a','b','c'],[1,2,3],['d','e','f'],[4,5,6]]
How can I get each element of a
to be an argument of say, zip
without having to type
zip(a[0],a[1],a[2],a[3])
?
The * symbol is used to pass a variable number of arguments to a function. Typically, this syntax is used to avoid the code failing when we don't know how many arguments will be sent to the function.
In Python, we can pass multiple arguments using some special symbols. The special symbols are: *args – used to pass a non-keyworded variable number of arguments to a function.
You can send any data types of argument to a function (string, number, list, dictionary etc.), and it will be treated as the same data type inside the function.
Functions can accept more than one argument. When calling a function, you're able to pass multiple arguments to the function; each argument gets stored in a separate parameter and used as a discrete variable within the function.
Using sequence unpacking (thanks to delnan for the name):
zip(*a)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With