擅长:python、mysql、java
<p>警告是关于在内部作用域中重新使用这些名称所带来的潜在危险。它会让你错过一个虫子。例如,考虑一下</p>
<pre><code>def sample_func(*args):
smaple = sum(args) # note the misspelling of `sample here`
print(sample * sample)
if __name__ == "__main__":
for sample in range(1, 5):
sample_func()
</code></pre>
<p>因为您使用了相同的名称,所以在函数中拼写错误不会导致错误。</p>
<p>当你的代码非常简单的时候,你就可以摆脱这种类型的事情而不会产生任何后果。但是,为了避免在更复杂的代码上出现错误,使用这些“最佳实践”是很好的。</p>