擅长:python、mysql、java
<p>
自从<a href="https://docs.python.org/3.0/whatsnew/3.0.html#builtins" rel="nofollow noreferrer">reduce() function has been moved to the module ^{<cd1>} python 3.0</a>以来,您必须采取不同的方法。</p>
<p>您可以使用<code>functools.reduce()</code>访问函数:</p>
<pre class="lang-python prettyprint-override"><code>product = functools.reduce(operator.mul, iterable, 1)
</code></pre>
<p>或者,如果您想遵循python团队的精神(他们删除了<code>reduce()</code>,因为他们认为<code>for</code>更具可读性),请使用循环:</p>
<pre class="lang-python prettyprint-override"><code>product = 1
for x in iterable:
product *= x
</code></pre>