擅长:python、mysql、java
<p><code>print</code>只是打印东西。如果你需要对结果做任何额外的处理,这不是你想要的。在</p>
<p><code>return</code>从函数返回一个值,以便将其添加到列表、存储在数据库中等。不打印任何内容</p>
<p>可能让您感到困惑的是<strong>Python解释器将打印返回值</strong>,因此,如果您所做的只是这些,那么它们可能会执行相同的操作。在</p>
<p>例如,假设您需要计算总赢款:</p>
<pre><code>def count_wins(teamname):
wins = 0
for team in nfl:
if team[2] == teamname:
wins +=1
return wins
total_wins = 0
for teamname in teamnames:
# doing stuff with result
total_wins += count_wins(teamname)
# now just print the total
print total_wins
</code></pre>
<hr/>
^{pr2}$