human定义一个求解阶乘的函数;利用列表生成式生成1-5的阶乘。使用Python
def factorial(n): if n == 0: return 1 else: return n * factorial(n-1)
factorials = [factorial(i) for i in range(1, 6)] print(factorials) # [1, 2, 6, 24, 120]
原文地址: https://www.cveoy.top/t/topic/fcVb 著作权归作者所有。请勿转载和采集!