what's the difference between f(a) and f(*a)

Q

qxyuestc

def sum1(*a): return(sum(i*i for i in a))
def sum2(a): return(sum(i*i for i in a))

a=[1,2,3]
print(sum1(*a), sum2(a))
####################################
showed above: the result from sum1() and sum2() is the same. So, what
is the difference between f(a) and f(*a)
 
M

Marc 'BlackJack' Rintsch

showed above: the result from sum1() and sum2() is the same. So, what is
the difference between f(a) and f(*a)

f(a) -> f([1, 2, 3])
f(*a) -> f(1, 2, 3)

Ciao,
Marc 'BlackJack' Rintsch
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,152
Latest member
LorettaGur
Top