把Python知识点整理成100道习题,知识点来自两本书:Python基础教程(第3版)和流畅的Python,以后会定期加入更多的习题,大家帮忙点个赞哈,点赞越多,更新越快~
通过 reduce 和 operator.mul 函数计算阶乘
>>> from functools import reduce
>>> from operator import mul
>>> def fact(n):
return reduce(mul, range(1, n+1))
>>> fact(5)
120