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/n5r0 著作权归作者所有。请勿转载和采集!
安全问答是一个知识全球问答,包含丰富的问答知识
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/n5r0 著作权归作者所有。请勿转载和采集!