25.4k views
5 votes
What does this function do? How to write a docstring for it?

def product(factors):
i = factors[0]
for p in factors[1:]:
i *= p
return i

User Arkascha
by
5.0k points

1 Answer

5 votes

Answer:

def product(factors):

'''Returns the product of all the numbers in the list factors.'''

i = factors[0]

for p in factors[1:]:

i *= p

return i

the docstring is a string that is the first statement in a function.

User Matt Bierner
by
5.6k points