在Python中,连乘通常使用乘法运算符 `*` 来表示。如果你想要计算一系列数字的乘积,你可以使用for循环结合乘法运算符,或者使用Python内置的 `functools.reduce` 函数和 `operator.mul` 函数。
n = 1
for i in range(1, N+1):
n *= i
print(n)
如果你想要使用 `functools.reduce` 函数,可以这样写:
from functools import reduce
import operator
numbers = [1, 2, 3, 4, 5] 你想要连乘的数字列表
product = reduce(operator.mul, numbers)
print(product)