降低

在 Python 3.x 中,已在此處解釋的 reduce 函式已從內建函式中刪除,現在必須從 functools 匯入。

from functools import reduce
def factorial(n):
    return reduce(lambda a, b: (a*b), range(1, n+1))