256,276 views
28 votes
28 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 Robert Fall
by
2.5k points

1 Answer

25 votes
25 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 Edlin
by
3.2k points